harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r820201 - /harmony/enhanced/classlib/trunk/modules/luni/src/main/native/launcher/shared/main.c
Date Wed, 30 Sep 2009 07:43:29 GMT
Author: hindessm
Date: Wed Sep 30 07:43:29 2009
New Revision: 820201

URL: http://svn.apache.org/viewvc?rev=820201&view=rev
Log:
Combine the strLen calculation and finding loops to optimise for the
highly likely case that both will happen.

Fix off-by-one error that occurs because the strLen calculation and
the separator concatenation logic were not consistent.  This occurred
if you did something like:

  LD_LIBRARY_PATH=$PWD/deploy/jdk/jre/bin/default deploy/jdk/jre/bin/java ...

where the first newPathToAdd is missing but the second is found
leaving strLen with the wrong number of separators.  (It occurred for
me because the first newPathToAdd requires a trailing slash while the
second does not and I provided both without slashes.  We should fix
this too.)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/launcher/shared/main.c

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/launcher/shared/main.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/launcher/shared/main.c?rev=820201&r1=820200&r2=820201&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/launcher/shared/main.c (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/launcher/shared/main.c Wed
Sep 30 07:43:29 2009
@@ -1073,8 +1073,8 @@
   int rc = 0;
   char *exeName;
   int found = 0;
-  int i=0;
-  int strLen;
+  int i = 0;
+  int strLen = 0;
 
 #ifndef HY_NO_THR
   PORT_ACCESS_FROM_PORT (portLibrary);
@@ -1096,10 +1096,13 @@
    *  see if we can find all paths in the current path
    */
     
-  for (i=0; i < count; i++) { 
-    if (newPathToAdd[i] != NULL
-        && findDirInPath(oldPath, newPathToAdd[i], separator) != 0) {
+  for (i=0; i < count; i++) {
+    if (newPathToAdd[i] != NULL) {
+      if (findDirInPath(oldPath, newPathToAdd[i], separator) != 0) {
         found++;
+      } else {
+        strLen += strlen(newPathToAdd[i]) + 1;
+      }
     }
   }
 
@@ -1116,15 +1119,7 @@
    *  short) and then add the old path on the end
    */
    
-  strLen = strlen(variableName) + strlen("=") + strlen(oldPath);
-  
-  for (i=0; i < count; i++) {
-    if (newPathToAdd[i] != NULL
-        && findDirInPath(oldPath, newPathToAdd[i],separator) == 0) {
-        strLen += strlen(newPathToAdd[i]);
-        strLen++; // for each separator
-    }
-  }
+  strLen += strlen(variableName) + strlen("=") + strlen(oldPath);
 
 #ifndef HY_NO_THR
   newPath = hymem_allocate_memory(strLen + 1);
@@ -1138,14 +1133,11 @@
   for (i=0; i < count; i++) { 
     if (newPathToAdd[i] != NULL
         && findDirInPath(oldPath, newPathToAdd[i], separator) == 0) {
-        if (i != 0) {
-            strcat(newPath, separator);
-        }
-        strcat(newPath, newPathToAdd[i]);
+      strcat(newPath, newPathToAdd[i]);
+      strcat(newPath, separator);
     }
   }
   
-  strcat(newPath, separator);
   strcat(newPath, oldPath);
 
   /* 



Mime
View raw message