chiark / gitweb /
bootchart: check return of strftime
authorThomas Hindoe Paaboel Andersen <phomes@gmail.com>
Sat, 27 Sep 2014 20:25:07 +0000 (22:25 +0200)
committerThomas Hindoe Paaboel Andersen <phomes@gmail.com>
Sun, 28 Sep 2014 12:46:38 +0000 (14:46 +0200)
Found by coverity. Fixes: CID#996314 and #996312

src/bootchart/bootchart.c
src/bootchart/svg.c

index 8ef5ad18a6ac742609fa83b1cd84098e6a77efe1..366a5ab5d0225b5d34ae68cfaba96cf9433974ab 100644 (file)
@@ -389,7 +389,9 @@ int main(int argc, char *argv[]) {
 
                 if (!of && (access(arg_output_path, R_OK|W_OK|X_OK) == 0)) {
                         t = time(NULL);
-                        strftime(datestr, sizeof(datestr), "%Y%m%d-%H%M", localtime(&t));
+                        r = strftime(datestr, sizeof(datestr), "%Y%m%d-%H%M", localtime(&t));
+                        assert_se(r > 0);
+
                         snprintf(output_file, PATH_MAX, "%s/bootchart-%s.svg", arg_output_path, datestr);
                         of = fopen(output_file, "we");
                 }
@@ -457,7 +459,9 @@ int main(int argc, char *argv[]) {
 
         if (!of) {
                 t = time(NULL);
-                strftime(datestr, sizeof(datestr), "%Y%m%d-%H%M", localtime(&t));
+                r = strftime(datestr, sizeof(datestr), "%Y%m%d-%H%M", localtime(&t));
+                assert_se(r > 0);
+
                 snprintf(output_file, PATH_MAX, "%s/bootchart-%s.svg", arg_output_path, datestr);
                 of = fopen(output_file, "we");
         }
index 135883fb838c813a932ff7fe5cf96fdbfd48f2f3..faf377e506e942f729a2b174c72c709bb9923710 100644 (file)
@@ -162,7 +162,7 @@ static void svg_title(const char *build) {
         char *c;
         FILE *f;
         time_t t;
-        int fd;
+        int fd, r;
         struct utsname uts;
 
         /* grab /proc/cmdline */
@@ -196,7 +196,8 @@ static void svg_title(const char *build) {
 
         /* date */
         t = time(NULL);
-        strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", localtime(&t));
+        r = strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", localtime(&t));
+        assert_se(r > 0);
 
         /* CPU type */
         fd = openat(procfd, "cpuinfo", O_RDONLY);