lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [5134] Resolve an ancient defect


From: Greg Chicares
Subject: [lmi-commits] [5134] Resolve an ancient defect
Date: Mon, 20 Dec 2010 23:55:20 +0000

Revision: 5134
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=5134
Author:   chicares
Date:     2010-12-20 23:55:20 +0000 (Mon, 20 Dec 2010)
Log Message:
-----------
Resolve an ancient defect

Modified Paths:
--------------
    lmi/trunk/ChangeLog
    lmi/trunk/getopt.cpp
    lmi/trunk/getopt_test.cpp

Modified: lmi/trunk/ChangeLog
===================================================================
--- lmi/trunk/ChangeLog 2010-12-20 23:13:13 UTC (rev 5133)
+++ lmi/trunk/ChangeLog 2010-12-20 23:55:20 UTC (rev 5134)
@@ -27081,3 +27081,16 @@
   ncnnnpnn_test.cpp
 Improve diagnosis of failing tests and treatment of borland issues.
 
+20101220T2313Z <address@hidden> [655]
+
+  getopt.cpp
+  getopt.hpp
+  getopt_test.cpp
+Remove a defunct URL.
+
+20101220T2355Z <address@hidden> [654]
+
+  getopt.cpp
+  getopt_test.cpp
+Resolve an ancient defect.
+

Modified: lmi/trunk/getopt.cpp
===================================================================
--- lmi/trunk/getopt.cpp        2010-12-20 23:13:13 UTC (rev 5133)
+++ lmi/trunk/getopt.cpp        2010-12-20 23:55:20 UTC (rev 5134)
@@ -355,6 +355,11 @@
 {
   optopt = 0;
 
+  // Without this early exit, a segfault occurs if 'nargc' is zero,
+  // as the unit test demonstrates.
+  if (0 == nargc)
+      return EOF;
+
   // We are processing a LIST_ARG or ALT_ARG,
   // now we try to see if the next argument is a current option value
   // or is another option.

Modified: lmi/trunk/getopt_test.cpp
===================================================================
--- lmi/trunk/getopt_test.cpp   2010-12-20 23:13:13 UTC (rev 5133)
+++ lmi/trunk/getopt_test.cpp   2010-12-20 23:55:20 UTC (rev 5134)
@@ -210,27 +210,24 @@
     char arg1[] = {"--verbose"};
     char arg2[] = {"xyz"};
     char* test_argv[] = {arg0, arg1, arg2, 0};
-    int test_argc = -1 + lmi_array_size(test_argv);
+    int test_argc = -1 + static_cast<int>(lmi_array_size(test_argv));
     std::string s = getopt_test::test(test_argc, test_argv);
     BOOST_TEST_EQUAL(s, "option verbose\nnon-option ARGV-elements: xyz\n");
     }
 
-#if 0
-// TODO ?? The standard permits 'argc' to be zero. However, this segfaults.
     {
     char* test_argv[] = {0};
-    int test_argc = -1 + lmi_array_size(test_argv);
+    int test_argc = -1 + static_cast<int>(lmi_array_size(test_argv));
     std::string s = getopt_test::test(test_argc, test_argv);
     BOOST_TEST_EQUAL(s, "");
     }
-#endif // 0
 
     {
     char arg0[] = {""};
     char arg1[] = {"-o"};
     char arg2[] = {"-d1,2,3"};
     char* test_argv[] = {arg0, arg1, arg2, 0};
-    int test_argc = -1 + lmi_array_size(test_argv);
+    int test_argc = -1 + static_cast<int>(lmi_array_size(test_argv));
     std::string s = getopt_test::test(test_argc, test_argv);
     BOOST_TEST_EQUAL(s, "option o\noption d with value '1,2,3'\n");
     }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]