]> Savannah Git Hosting - gnulib.git/commitdiff
parse-datetime: restrict debug output to input string
authorPádraig Brady <P@draigBrady.com>
Thu, 8 Sep 2016 14:17:10 +0000 (15:17 +0100)
committerPádraig Brady <P@draigBrady.com>
Thu, 8 Sep 2016 14:24:11 +0000 (15:24 +0100)
* lib/parse-datetime.y (parse_datetime2): If we parse
all of the input but determine it's invalid, ensure
we don't output the now invalid input pointer.
This issue was seen with `date -d 'now +1'`.

ChangeLog
lib/parse-datetime.y

index 3c65fdea4d08e75bc506663c7d72882855e4288f..e02ca0cea6c8ae4d35bf6e800e9a4153b4c77805 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2016-09-08  Pádraig Brady  <P@draigBrady.com>
+
+       parse-datetime: restrict debug output to input string
+       * lib/parse-datetime.y (parse_datetime2): If we parse
+       all of the input but determine it's invalid, ensure
+       we don't output the now invalid input pointer.
+       This issue was seen with `date -d 'now +1'`.
+
 2016-09-07  Paul Eggert  <eggert@cs.ucla.edu>
 
        flexmember: new macro FLEXALIGNOF
index 152cb412c93b9b29734b9f8259f22eb647ef750f..997895555ce8cc02a8b9cb42daad92ab45cb6ce6 100644 (file)
@@ -1704,6 +1704,7 @@ parse_datetime2 (struct timespec *result, char const *p,
   bool ok = true;
   char dbg_ord[DBGBUFSIZE];
   char dbg_tm[DBGBUFSIZE];
+  char const *input_sentinel = p + strlen (p);
 
   if (! now)
     {
@@ -1862,7 +1863,15 @@ parse_datetime2 (struct timespec *result, char const *p,
   if (yyparse (&pc) != 0)
     {
       if (pc.parse_datetime_debug)
-        dbg_printf (_("error: parsing failed, stopped at '%s'\n"), pc.input);
+        {
+          if (input_sentinel <= pc.input)
+            dbg_printf (_("error: parsing failed\n"), pc.input);
+          else
+            {
+              dbg_printf (_("error: parsing failed, stopped at '%s'\n"),
+                          pc.input);
+            }
+         }
       goto fail;
     }