diff options
author | Elliott Hughes <enh@google.com> | 2015-03-01 16:11:50 -0600 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2015-03-01 16:11:50 -0600 |
commit | 4bbec1e41580c9200cae03c9549fb032596b2b30 (patch) | |
tree | 45ea03d57414302ec8bfe7ca40e591500ae35bc6 | |
parent | 30c36d87280f3c45db157056b94ff67922f03fbf (diff) | |
download | toybox-4bbec1e41580c9200cae03c9549fb032596b2b30.tar.gz |
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.
-rw-r--r-- | toys/pending/tar.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/toys/pending/tar.c b/toys/pending/tar.c index dc1480c4..8b5f443e 100644 --- a/toys/pending/tar.c +++ b/toys/pending/tar.c @@ -94,7 +94,7 @@ static void copy_in_out(int src, int dst, off_t size) 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 @@ static void write_longname(struct archive_handler *tar, char *name, char type) 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 @@ static void add_file(struct archive_handler *tar, char **nam, struct stat *st) 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 @@ static void add_file(struct archive_handler *tar, char **nam, struct stat *st) 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 @@ static void add_file(struct archive_handler *tar, char **nam, struct stat *st) 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)) |