]> granicus.if.org Git - graphviz/commitdiff
remove fallback "%?%K" strftime format in expr’s printf
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 8 Aug 2021 22:20:11 +0000 (15:20 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 12 Aug 2021 14:48:36 +0000 (07:48 -0700)
lib/expr’s printf implementation supports a "%t" format code to print a time. If
no format is provided for this, it would fallback to a default of "%?%K".

While working on #1998, one of my intermediate refactorings moved this string
literal into the actual call to strftime. At this point the compiler politely
interjected that neither "%?" nor "%K" are format strings understood by
strftime. So it seems this results in an invalid call to strftime.

To deal with this, we now throw an error when this function is called with no
format string instead of making an invalid strftime call.

CHANGELOG.md
lib/expr/exeval.c

index aad5d05c4aee30d4a1d716622b8c0dbc9b118d01..1e1c2e054ef7511facc4637317787b2b67df991a 100644 (file)
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - `edgepaint` accepts more standard `--` prefixed command line arguments and
   rejects invalid options #1971
 - improved detection of Lefty dependencies in the Autotools build system
+- libexpr rejects printing the time (`%t`) if no format is provided
 
 ### Fixed
 
index ea7fc9e331a1e1ea8601f6bcdfaca7f01d287338..6b4ce791c96fe0fb23c575ab13e31769e3e3e6eb 100644 (file)
@@ -348,12 +348,14 @@ prformat(Sfio_t* sp, void* vp, Sffmt_t* dp)
        case 'T':
                if ((tm = *(Sflong_t*)vp) == -1)
                        tm = time(NULL);
-        if (!txt)
-            txt = "%?%K";
-        s = fmtbuf(TIME_LEN);
-        stm = localtime(&tm);
-        strftime(s, TIME_LEN, txt, stm);
-        *(char **)vp = s;
+        if (!txt) {
+            exerror("printf: no time format provided");
+        } else {
+            s = fmtbuf(TIME_LEN);
+            stm = localtime(&tm);
+            strftime(s, TIME_LEN, txt, stm);
+            *(char **)vp = s;
+        }
                dp->fmt = 's';
                dp->size = -1;
                break;