* based on code from util-linux v 2.11l
*
* Copyright (c) 1989
- * The Regents of the University of California. All rights reserved.
+ * The Regents of the University of California. All rights reserved.
*
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
*
* Original copyright notice is retained at the end of this file.
*/
* skip any special chars -- save precision in
* case it's a %s format.
*/
- while (strchr(index_str + 1, *++fmt));
+ while (strchr(index_str + 1, *++fmt))
+ continue;
if (*fmt == '.' && isdigit(*++fmt)) {
prec = atoi(fmt);
while (isdigit(*++fmt))
return cur_size;
}
-static void rewrite(priv_dumper_t *dumper, FS *fs)
+static NOINLINE void rewrite(priv_dumper_t *dumper, FS *fs)
{
enum { NOTOKAY, USEBCNT, USEPREC } sokay;
- PR *pr, **nextpr = NULL;
FU *fu;
+ PR *pr;
char *p1, *p2, *p3;
char savech, *fmtp;
const char *byte_count_str;
* break each format unit into print units; each
* conversion character gets its own.
*/
- for (nconv = 0, fmtp = fu->fmt; *fmtp; nextpr = &pr->nextpr) {
+ for (nconv = 0, fmtp = fu->fmt; *fmtp; ) {
/* NOSTRICT */
/* DBU:[dvae@cray.com] zalloc so that forward ptrs start out NULL*/
pr = xzalloc(sizeof(PR));
if (!fu->nextpr)
fu->nextpr = pr;
- /* ignore nextpr -- its unused inside the loop and is
- * uninitialized 1st time through.
- */
/* skip preceding text and up to the next % sign */
for (p1 = fmtp; *p1 && *p1 != '%'; ++p1)
pr->bcnt = fu->bcnt;
} else if (sokay == USEPREC) {
pr->bcnt = prec;
- } else { /* NOTOKAY */
+ } else { /* NOTOKAY */
bb_error_msg_and_die("%%s requires a precision or a byte count");
}
} else if (*p1 == '_') {
* interprets any data at all, and has no iteration count,
* repeat it as necessary.
*
- * if, rep count is greater than 1, no trailing whitespace
+ * if rep count is greater than 1, no trailing whitespace
* gets output from the last iteration of the format unit.
*/
- for (fu = fs->nextfu;; fu = fu->nextfu) {
- if (!fu->nextfu && fs->bcnt < dumper->blocksize
- && !(fu->flags & F_SETREP) && fu->bcnt
+ for (fu = fs->nextfu; fu; fu = fu->nextfu) {
+ if (!fu->nextfu
+ && fs->bcnt < dumper->blocksize
+ && !(fu->flags & F_SETREP)
+ && fu->bcnt
) {
fu->reps += (dumper->blocksize - fs->bcnt) / fu->bcnt;
}
- if (fu->reps > 1) {
+ if (fu->reps > 1 && fu->nextpr) {
for (pr = fu->nextpr;; pr = pr->nextpr)
if (!pr->nextpr)
break;
struct stat sbuf;
if (statok) {
- if (fstat(STDIN_FILENO, &sbuf)) {
- bb_simple_perror_msg_and_die(fname);
- }
+ xfstat(STDIN_FILENO, &sbuf, fname);
if (!(S_ISCHR(sbuf.st_mode) || S_ISBLK(sbuf.st_mode) || S_ISFIFO(sbuf.st_mode))
&& dumper->pub.dump_skip >= sbuf.st_size
) {
return;
}
}
- if (fseek(stdin, dumper->pub.dump_skip, SEEK_SET)) {
+ if (fseeko(stdin, dumper->pub.dump_skip, SEEK_SET)) {
bb_simple_perror_msg_and_die(fname);
}
dumper->address += dumper->pub.dump_skip;
for (;;) {
if (*dumper->argv) {
+ dumper->next__done = statok = 1;
if (!(freopen(*dumper->argv, "r", stdin))) {
bb_simple_perror_msg(*dumper->argv);
dumper->exitval = 1;
++dumper->argv;
continue;
}
- dumper->next__done = statok = 1;
} else {
if (dumper->next__done)
- return 0;
+ return 0; /* no next file */
dumper->next__done = 1;
statok = 0;
}
{
int n;
int need, nread;
- unsigned char *tmpp;
int blocksize = dumper->blocksize;
if (!dumper->get__curp) {
dumper->address = (off_t)0; /*DBU:[dave@cray.com] initialize,initialize..*/
dumper->get__curp = xmalloc(blocksize);
- dumper->get__savp = xmalloc(blocksize);
+ dumper->get__savp = xzalloc(blocksize); /* need to be initialized */
} else {
- tmpp = dumper->get__curp;
+ unsigned char *tmp = dumper->get__curp;
dumper->get__curp = dumper->get__savp;
- dumper->get__savp = tmpp;
+ dumper->get__savp = tmp;
dumper->savaddress += blocksize;
dumper->address = dumper->savaddress;
}
static const char conv_str[] ALIGN1 =
"\0\\0\0"
- "\007\\a\0" /* \a */
+ "\007\\a\0" /* \a */
"\b\\b\0"
"\f\\b\0"
"\n\\n\0"
str += 4;
} while (*str);
- if (isprint(*p)) {
+ if (isprint_asciionly(*p)) {
*pr->cchar = 'c';
printf(pr->fmt, *p);
} else {
sprintf(buf, "%03o", (int) *p);
str = buf;
- strpr:
+ strpr:
*pr->cchar = 's';
printf(pr->fmt, str);
}
} else if (*p == 0x7f) {
*pr->cchar = 's';
printf(pr->fmt, "del");
- } else if (isprint(*p)) {
+ } else if (*p < 0x7f) { /* isprint() */
*pr->cchar = 'c';
printf(pr->fmt, *p);
} else {
switch (pr->bcnt) {
case 4:
- memmove(&fval, bp, sizeof(fval));
+ memcpy(&fval, bp, sizeof(fval));
printf(pr->fmt, fval);
break;
case 8:
- memmove(&dval, bp, sizeof(dval));
+ memcpy(&dval, bp, sizeof(dval));
printf(pr->fmt, dval);
break;
}
printf(pr->fmt, (int) *bp);
break;
case 2:
- memmove(&sval, bp, sizeof(sval));
+ memcpy(&sval, bp, sizeof(sval));
printf(pr->fmt, (int) sval);
break;
case 4:
- memmove(&ival, bp, sizeof(ival));
+ memcpy(&ival, bp, sizeof(ival));
printf(pr->fmt, ival);
break;
}
break;
}
case F_P:
- printf(pr->fmt, isprint(*bp) ? *bp : '.');
+ printf(pr->fmt, isprint_asciionly(*bp) ? *bp : '.');
break;
case F_STR:
printf(pr->fmt, (char *) bp);
printf(pr->fmt, (unsigned) *bp);
break;
case 2:
- memmove(&sval, bp, sizeof(sval));
+ memcpy(&sval, bp, sizeof(sval));
printf(pr->fmt, (unsigned) sval);
break;
case 4:
- memmove(&ival, bp, sizeof(ival));
+ memcpy(&ival, bp, sizeof(ival));
printf(pr->fmt, ival);
break;
}
nextfupp = &tfs->nextfu;
/* take the format string and break it up into format units */
- for (p = fmt;;) {
+ p = fmt;
+ for (;;) {
p = skip_whitespace(p);
- if (!*p) {
+ if (*p == '\0') {
break;
}
/* skip slash and trailing white space */
if (*p == '/') {
- p = skip_whitespace(++p);
+ p = skip_whitespace(p + 1);
}
/* byte count */
}
tfu->bcnt = atoi(savep);
/* skip trailing white space */
- p = skip_whitespace(++p);
+ p = skip_whitespace(p + 1);
}
/* format */
bb_error_msg_and_die("bad format {%s}", fmt);
}
for (savep = ++p; *p != '"';) {
- if (*p++ == 0) {
+ if (*p++ == '\0') {
bb_error_msg_and_die("bad format {%s}", fmt);
}
}
/* alphabetic escape sequences have to be done in place */
for (p2 = p1;; ++p1, ++p2) {
- if (!*p1) {
+ if (*p1 == '\0') {
*p2 = *p1;
break;
}