summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjjin9 <jjin9@6f19259b-4bc3-4df7-8a09-765794883524>2006-09-07 02:37:43 +0000
committerjjin9 <jjin9@6f19259b-4bc3-4df7-8a09-765794883524>2006-09-07 02:37:43 +0000
commit67ce7c51e719e82ef5be38aca6bb65588b73c016 (patch)
treecd6bc7c53766c893d54c0d5922fa8832d2c92a3d
parent68a05456c3b70053704f3046a6f20e4d8ca7274a (diff)
downloadedk2-67ce7c51e719e82ef5be38aca6bb65588b73c016.zip
edk2-67ce7c51e719e82ef5be38aca6bb65588b73c016.tar.gz
edk2-67ce7c51e719e82ef5be38aca6bb65588b73c016.tar.bz2
There is a potential flaw in HelpInfo.java previously. It use String[substrnum] to save the result of splitString(), the substrnum is calculated approximatively and has to be set larger enough to provide sufficient space. So substrnum relate to the string specifically.
In this version, it use ListedList to implement the splitString(), which is independent of string specifically. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1488 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r--Tools/Source/ContextTool/org/tianocore/context/HelpInfo.java35
1 files changed, 16 insertions, 19 deletions
diff --git a/Tools/Source/ContextTool/org/tianocore/context/HelpInfo.java b/Tools/Source/ContextTool/org/tianocore/context/HelpInfo.java
index 92526a5..99af925 100644
--- a/Tools/Source/ContextTool/org/tianocore/context/HelpInfo.java
+++ b/Tools/Source/ContextTool/org/tianocore/context/HelpInfo.java
@@ -13,6 +13,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
package org.tianocore.context;
+import java.util.LinkedList;
+
public class HelpInfo {
@@ -39,17 +41,13 @@ public class HelpInfo {
* @return no return value
**/
private static void outputSubUsageInfo(String str1, String str2) {
+
splitString(str2);
- if (substrnum > 0) {
- System.out.printf("\n%4s %-30s %s", "", str1, substr[0]);
- for (int i = 1; i < substrnum; i++) {
- if (substr[i] != null)
- System.out.printf("\n%4s %-30s %s", "", "", substr[i]);
- }
- substrnum = 0;
- } else {
- System.out.printf("\n%4s %-30s %s", "", str1, str2);
+ System.out.printf("\n%4s %-30s %s", "", str1, List.get(0));
+ for (int i=1; i<List.size(); i++){
+ System.out.printf("\n%4s %-30s %s", "", "", List.get(i));
}
+ List.clear();
}
/**
@@ -60,31 +58,30 @@ public class HelpInfo {
private static void splitString(String str) {
int strlength = str.length();
if (strlength > MaxSrtingLength) {
-
- //we should modify the array to list, for it is strange to + 2
- substrnum = strlength / MaxSrtingLength + 2;
String[] tokens = str.split("[ ]", 0);
- substr = new String[substrnum];
+ String tempstr = null;
int templength = 0;
- int j = 0;
int start = 0;
int end = 0;
for (int i = 0; i < tokens.length; i++) {
if ((templength = end + tokens[i].length() + 1) < (MaxSrtingLength + start)) {
end = templength;
} else {
- substr[j++] = str.substring(start, end);
+ tempstr = str.substring(start, end);
+ List.add(tempstr);
start = end;
i = i - 1;
}
}
- substr[j] = str.substring(start, end - 1);
+ tempstr = str.substring(start, end - 1);
+ List.add(tempstr);
+ } else {
+ List.add(str);
}
}
- private static String[] substr = null;
-
- private static int substrnum = 0;
+
+ private static LinkedList<String> List = new LinkedList<String>();
private static final int MaxSrtingLength = 40;