From 781cea6aa1faa6a1aa04d6c06146d82993fc7c9d Mon Sep 17 00:00:00 2001 From: Jeff Welch Date: Fri, 17 May 2013 21:28:38 -0700 Subject: [PATCH] Fix extra element bug with $_SERVER['argc'] and $_SERVER['argv'] When a file is executed on the command line without the --file argument, $_SERVER['argv'] contains an extraneous empty string at the beginning of the array. (Note this bug does not occur when the --file argument is used.) Github pull request 767: https://github.com/facebook/hiphop-php/pull/767 --- hphp/runtime/base/builtin_functions.cpp | 4 +--- hphp/runtime/base/program_functions.cpp | 6 +++--- hphp/test/slow/program_functions/1235.php | 4 ++-- hphp/test/slow/program_functions/1235.php.expect | 2 ++ 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/hphp/runtime/base/builtin_functions.cpp b/hphp/runtime/base/builtin_functions.cpp index 0eb8e40bc..1131f8882 100644 --- a/hphp/runtime/base/builtin_functions.cpp +++ b/hphp/runtime/base/builtin_functions.cpp @@ -1047,11 +1047,9 @@ Variant invoke_file(CStrRef s, bool once, const char *currentDir) { SystemGlobals* g = (SystemGlobals*)get_global_variables(); Variant& v_argc = g->GV(argc); Variant& v_argv = g->GV(argv); - if (!more(v_argc, int64_t(1))) { + if (!more(v_argc, int64_t(0))) { return true; } - v_argc--; - v_argv.dequeue(); String s2 = toString(v_argv.rvalAt(int64_t(0), AccessFlags::Error)); if (invoke_file_impl(r, s2, once, "")) { return r; diff --git a/hphp/runtime/base/program_functions.cpp b/hphp/runtime/base/program_functions.cpp index c4e8512da..daac9395d 100644 --- a/hphp/runtime/base/program_functions.cpp +++ b/hphp/runtime/base/program_functions.cpp @@ -683,7 +683,7 @@ static void prepare_args(int &argc, char **&argv, const StringVec &args, const char *file) { argv = (char **)malloc((args.size() + 2) * sizeof(char*)); argc = 0; - if (file) { + if (*file) { argv[argc++] = (char*)file; } for (int i = 0; i < (int)args.size(); i++) { @@ -1031,8 +1031,8 @@ static int execute_program_impl(int argc, char **argv) { if (!po.file.empty()) { Repo::setCliFile(po.file); - } else if (new_argc >= 2) { - Repo::setCliFile(new_argv[1]); + } else if (new_argc >= 1) { + Repo::setCliFile(new_argv[0]); } int ret = 0; diff --git a/hphp/test/slow/program_functions/1235.php b/hphp/test/slow/program_functions/1235.php index 586d5454a..8a115dffe 100644 --- a/hphp/test/slow/program_functions/1235.php +++ b/hphp/test/slow/program_functions/1235.php @@ -1,3 +1,3 @@