瀏覽代碼

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 年之前
父節點
當前提交
441f7b7fab
共有 2 個文件被更改,包括 4 次插入2 次删除
  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
 $JS = <<< EOT
 var foo = require("foo/test");
 var foo = require("foo/test");
 var foo = require("foo/bar/baz/test");
 var foo = require("foo/bar/baz/test");
+var foo = require("foo//bar//baz//blub");
 EOT;
 EOT;
 
 
 $v8 = new V8Js();
 $v8 = new V8Js();
@@ -22,4 +23,5 @@ $v8->executeString($JS, 'module.js');
 --EXPECT--
 --EXPECT--
 setModuleLoader called for foo/test
 setModuleLoader called for foo/test
 setModuleLoader called for foo/bar/baz/test
 setModuleLoader called for foo/bar/baz/test
+setModuleLoader called for foo/bar/baz/blub
 ===EOF===
 ===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) {
     while (*identifier > 0) {
         if (*identifier == '/') {
         if (*identifier == '/') {
-            if (strlen(term) > 0) {
+            if (ptr > term) {
                 // Terminate term string and add to terms vector
                 // Terminate term string and add to terms vector
                 *ptr++ = 0;
                 *ptr++ = 0;
                 terms.push_back(estrdup(term));
                 terms.push_back(estrdup(term));
@@ -47,7 +47,7 @@ static void v8js_commonjs_split_terms(const char *identifier, std::vector<char *
         identifier++;
         identifier++;
     }
     }
 
 
-    if (strlen(term) > 0) {
+    if (ptr > term) {
         // Terminate term string and add to terms vector
         // Terminate term string and add to terms vector
         *ptr++ = 0;
         *ptr++ = 0;
         terms.push_back(estrdup(term));
         terms.push_back(estrdup(term));