changeset 1715:a471f338b055 draft

fix format problems in tar.c %o is unsigned, but off_t is signed. * takes an int. an error_msg call was missing an argument. only one of these is an actual error, but i'd like to fix the others too so that we (toybox, but if not, then Android) can turn on format string warnings to prevent future bugs like the stat.c LP32 ones.
author Elliott Hughes <enh@google.com>
date Sun, 01 Mar 2015 16:11:50 -0600
parents 0c8ef714cf03
children ef5d02d0d37f
files toys/pending/tar.c
diffstat 1 files changed, 10 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/toys/pending/tar.c	Sun Mar 01 16:08:51 2015 -0600
+++ b/toys/pending/tar.c	Sun Mar 01 16:11:50 2015 -0600
@@ -94,7 +94,7 @@
 static void itoo(char *str, int len, off_t val)
 {
   char *t, tmp[sizeof(off_t)*3+1];
-  int cnt  = sprintf(tmp, "%0*llo", len, val);
+  int cnt  = sprintf(tmp, "%0*llo", len, (unsigned long long)val);
 
   t = tmp + cnt - len;
   if (*t == '0') t++;
@@ -130,11 +130,11 @@
 
   memset(&tmp, 0, sizeof(tmp));
   strcpy(tmp.name, "././@LongLink");
-  sprintf(tmp.mode, "%0*d", sizeof(tmp.mode)-1, 0);
-  sprintf(tmp.uid, "%0*d", sizeof(tmp.uid)-1, 0);
-  sprintf(tmp.gid, "%0*d", sizeof(tmp.gid)-1, 0);
-  sprintf(tmp.size, "%0*d", sizeof(tmp.size)-1, 0);
-  sprintf(tmp.mtime, "%0*d", sizeof(tmp.mtime)-1, 0);
+  sprintf(tmp.mode, "%0*d", (int)sizeof(tmp.mode)-1, 0);
+  sprintf(tmp.uid, "%0*d", (int)sizeof(tmp.uid)-1, 0);
+  sprintf(tmp.gid, "%0*d", (int)sizeof(tmp.gid)-1, 0);
+  sprintf(tmp.size, "%0*d", (int)sizeof(tmp.size)-1, 0);
+  sprintf(tmp.mtime, "%0*d", (int)sizeof(tmp.mtime)-1, 0);
   itoo(tmp.size, sizeof(tmp.size), sz);
   tmp.type = type;
   memset(tmp.chksum, ' ', 8);
@@ -184,7 +184,7 @@
   while ((c = strstr(hname, "../"))) hname = c + 3;
   if (warn && hname != name) {
     printf("removing leading '%.*s' "
-        "from member names\n",hname-name, name);
+        "from member names\n", (int)(hname-name), name);
     warn = 0;
   }
 
@@ -208,7 +208,8 @@
     if (st->st_size <= (off_t)0777777777777LL)
       itoo(hdr.size, sizeof(hdr.size), st->st_size);
     else {
-      error_msg("can't store file '%s' of size '%d'\n", hname, st->st_size);
+      error_msg("can't store file '%s' of size '%lld'\n",
+                hname, (unsigned long long)st->st_size);
       return;
     }
   } else if (S_ISLNK(st->st_mode)) {
@@ -229,7 +230,7 @@
     itoo(hdr.major, sizeof(hdr.major), major(st->st_rdev));
     itoo(hdr.minor, sizeof(hdr.minor), minor(st->st_rdev));
   } else {
-    error_msg("unknown file type '%s'");
+    error_msg("unknown file type '%o'", st->st_mode & S_IFMT);
     return;
   }
   if (strlen(hname) > sizeof(hdr.name))