Przeglądaj źródła

v8js_commonjs_split_terms: use pointer comparison instead of strlen

The strlen usage on term obviously was wrong here, since the term
string is not null-terminated at that place.
Stefan Siegl 9 lat temu
rodzic
commit
441f7b7fab
2 zmienionych plików z 4 dodań i 2 usunięć
  1. 2 0
      tests/commonjs_normalise_003.phpt
  2. 2 2
      v8js_commonjs.cc

+ 2 - 0
tests/commonjs_normalise_003.phpt

@@ -8,6 +8,7 @@ Test V8Js::setModuleLoader : Path normalisation #003
 $JS = <<< EOT
 var foo = require("foo/test");
 var foo = require("foo/bar/baz/test");
+var foo = require("foo//bar//baz//blub");
 EOT;
 
 $v8 = new V8Js();
@@ -22,4 +23,5 @@ $v8->executeString($JS, 'module.js');
 --EXPECT--
 setModuleLoader called for foo/test
 setModuleLoader called for foo/bar/baz/test
+setModuleLoader called for foo/bar/baz/blub
 ===EOF===

+ 2 - 2
v8js_commonjs.cc

@@ -31,7 +31,7 @@ static void v8js_commonjs_split_terms(const char *identifier, std::vector<char *
 
     while (*identifier > 0) {
         if (*identifier == '/') {
-            if (strlen(term) > 0) {
+            if (ptr > term) {
                 // Terminate term string and add to terms vector
                 *ptr++ = 0;
                 terms.push_back(estrdup(term));
@@ -47,7 +47,7 @@ static void v8js_commonjs_split_terms(const char *identifier, std::vector<char *
         identifier++;
     }
 
-    if (strlen(term) > 0) {
+    if (ptr > term) {
         // Terminate term string and add to terms vector
         *ptr++ = 0;
         terms.push_back(estrdup(term));