2006-07-03 01:17:05 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
2017-10-05 19:03:28 +05:30
|
|
|
/*
|
|
|
|
* uncompress for busybox -- (c) 2002 Robert Griebl
|
2002-05-20 00:30:14 +05:30
|
|
|
*
|
2004-03-15 13:59:22 +05:30
|
|
|
* based on the original compress42.c source
|
2002-05-20 00:30:14 +05:30
|
|
|
* (see disclaimer below)
|
|
|
|
*/
|
|
|
|
/* (N)compress42.c - File compression ala IEEE Computer, Mar 1992.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Spencer W. Thomas (decvax!harpo!utah-cs!utah-gr!thomas)
|
|
|
|
* Jim McKie (decvax!mcvax!jim)
|
|
|
|
* Steve Davies (decvax!vax135!petsd!peora!srd)
|
|
|
|
* Ken Turkowski (decvax!decwrl!turtlevax!ken)
|
|
|
|
* James A. Woods (decvax!ihnp4!ames!jaw)
|
|
|
|
* Joe Orost (decvax!vax135!petsd!joe)
|
|
|
|
* Dave Mack (csu@alembic.acs.com)
|
|
|
|
* Peter Jannesen, Network Communication Systems
|
|
|
|
* (peter@ncs.nl)
|
|
|
|
*
|
|
|
|
* marc@suse.de : a small security fix for a buffer overflow
|
|
|
|
*
|
|
|
|
* [... History snipped ...]
|
|
|
|
*/
|
2008-08-05 18:40:34 +05:30
|
|
|
#include "libbb.h"
|
2011-09-22 16:15:14 +05:30
|
|
|
#include "bb_archive.h"
|
2008-08-05 18:40:34 +05:30
|
|
|
|
|
|
|
|
2004-04-14 23:21:38 +05:30
|
|
|
/* Default input buffer size */
|
2010-10-28 22:27:19 +05:30
|
|
|
#define IBUFSIZ 2048
|
2002-11-28 14:39:47 +05:30
|
|
|
|
|
|
|
/* Default output buffer size */
|
2010-10-28 22:27:19 +05:30
|
|
|
#define OBUFSIZ 2048
|
2002-11-28 14:39:47 +05:30
|
|
|
|
|
|
|
/* Defines for third byte of header */
|
2007-06-10 20:38:44 +05:30
|
|
|
#define BIT_MASK 0x1f /* Mask for 'number of compresssion bits' */
|
|
|
|
/* Masks 0x20 and 0x40 are free. */
|
|
|
|
/* I think 0x20 should mean that there is */
|
|
|
|
/* a fourth header byte (for expansion). */
|
|
|
|
#define BLOCK_MODE 0x80 /* Block compression if table is full and */
|
|
|
|
/* compression rate is dropping flush tables */
|
|
|
|
/* the next two codes should not be changed lightly, as they must not */
|
|
|
|
/* lie within the contiguous general code space. */
|
|
|
|
#define FIRST 257 /* first free entry */
|
|
|
|
#define CLEAR 256 /* table clear output code */
|
2002-11-28 14:39:47 +05:30
|
|
|
|
2007-06-10 20:38:44 +05:30
|
|
|
#define INIT_BITS 9 /* initial number of bits/code */
|
2002-05-20 00:30:14 +05:30
|
|
|
|
|
|
|
|
2007-06-10 20:38:44 +05:30
|
|
|
/* machine variants which require cc -Dmachine: pdp11, z8000, DOS */
|
|
|
|
#define HBITS 17 /* 50% occupancy */
|
|
|
|
#define HSIZE (1<<HBITS)
|
|
|
|
#define HMASK (HSIZE-1) /* unused */
|
|
|
|
#define HPRIME 9941 /* unused */
|
|
|
|
#define BITS 16
|
|
|
|
#define BITS_STR "16"
|
|
|
|
#undef MAXSEG_64K /* unused */
|
|
|
|
#define MAXCODE(n) (1L << (n))
|
|
|
|
|
|
|
|
#define htabof(i) htab[i]
|
|
|
|
#define codetabof(i) codetab[i]
|
|
|
|
#define tab_prefixof(i) codetabof(i)
|
|
|
|
#define tab_suffixof(i) ((unsigned char *)(htab))[i]
|
|
|
|
#define de_stack ((unsigned char *)&(htab[HSIZE-1]))
|
|
|
|
#define clear_tab_prefixof() memset(codetab, 0, 256)
|
2002-05-20 00:30:14 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Decompress stdin to stdout. This routine adapts to the codes in the
|
|
|
|
* file building the "string" table on-the-fly; requiring no table to
|
2007-06-10 20:38:44 +05:30
|
|
|
* be stored in the compressed file.
|
2002-05-20 00:30:14 +05:30
|
|
|
*/
|
|
|
|
|
2009-04-21 16:39:40 +05:30
|
|
|
IF_DESKTOP(long long) int FAST_FUNC
|
2014-12-07 05:14:00 +05:30
|
|
|
unpack_Z_stream(transformer_state_t *xstate)
|
2002-05-20 00:30:14 +05:30
|
|
|
{
|
2009-04-21 16:39:40 +05:30
|
|
|
IF_DESKTOP(long long total_written = 0;)
|
|
|
|
IF_DESKTOP(long long) int retval = -1;
|
2002-11-28 14:39:47 +05:30
|
|
|
unsigned char *stackp;
|
|
|
|
int finchar;
|
2007-04-14 04:52:00 +05:30
|
|
|
long oldcode;
|
|
|
|
long incode;
|
2002-11-28 14:39:47 +05:30
|
|
|
int inbits;
|
|
|
|
int posbits;
|
|
|
|
int outpos;
|
|
|
|
int insize;
|
|
|
|
int bitmask;
|
2007-04-14 04:52:00 +05:30
|
|
|
long free_ent;
|
|
|
|
long maxcode;
|
|
|
|
long maxmaxcode;
|
2002-11-28 14:39:47 +05:30
|
|
|
int n_bits;
|
|
|
|
int rsize = 0;
|
2007-06-10 20:38:44 +05:30
|
|
|
unsigned char *inbuf; /* were eating insane amounts of stack - */
|
|
|
|
unsigned char *outbuf; /* bad for some embedded targets */
|
|
|
|
unsigned char *htab;
|
|
|
|
unsigned short *codetab;
|
2007-01-06 01:19:02 +05:30
|
|
|
|
|
|
|
/* Hmm, these were statics - why?! */
|
|
|
|
/* user settable max # bits/code */
|
|
|
|
int maxbits; /* = BITS; */
|
|
|
|
/* block compress mode -C compatible with 2.0 */
|
|
|
|
int block_mode; /* = BLOCK_MODE; */
|
|
|
|
|
2014-12-07 05:14:00 +05:30
|
|
|
if (check_signature16(xstate, COMPRESS_MAGIC))
|
2012-03-06 20:57:48 +05:30
|
|
|
return -1;
|
|
|
|
|
2007-06-10 20:38:44 +05:30
|
|
|
inbuf = xzalloc(IBUFSIZ + 64);
|
|
|
|
outbuf = xzalloc(OBUFSIZ + 2048);
|
2012-03-06 20:53:50 +05:30
|
|
|
htab = xzalloc(HSIZE); /* wasn't zeroed out before, maybe can xmalloc? */
|
2007-06-10 20:38:44 +05:30
|
|
|
codetab = xzalloc(HSIZE * sizeof(codetab[0]));
|
2002-05-20 00:30:14 +05:30
|
|
|
|
|
|
|
insize = 0;
|
|
|
|
|
2007-01-06 01:19:02 +05:30
|
|
|
/* xread isn't good here, we have to return - caller may want
|
|
|
|
* to do some cleanup (e.g. delete incomplete unpacked file etc) */
|
2014-12-07 05:14:00 +05:30
|
|
|
if (full_read(xstate->src_fd, inbuf, 1) != 1) {
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg("short read");
|
2007-06-10 20:38:44 +05:30
|
|
|
goto err;
|
2007-01-06 01:19:02 +05:30
|
|
|
}
|
2002-05-20 00:30:14 +05:30
|
|
|
|
|
|
|
maxbits = inbuf[0] & BIT_MASK;
|
|
|
|
block_mode = inbuf[0] & BLOCK_MODE;
|
|
|
|
maxmaxcode = MAXCODE(maxbits);
|
|
|
|
|
2002-11-28 14:39:47 +05:30
|
|
|
if (maxbits > BITS) {
|
2007-01-06 01:19:02 +05:30
|
|
|
bb_error_msg("compressed with %d bits, can only handle "
|
2007-06-10 20:38:44 +05:30
|
|
|
BITS_STR" bits", maxbits);
|
|
|
|
goto err;
|
2002-05-20 00:30:14 +05:30
|
|
|
}
|
|
|
|
|
2007-01-06 01:19:02 +05:30
|
|
|
n_bits = INIT_BITS;
|
|
|
|
maxcode = MAXCODE(INIT_BITS) - 1;
|
|
|
|
bitmask = (1 << INIT_BITS) - 1;
|
2002-05-20 00:30:14 +05:30
|
|
|
oldcode = -1;
|
|
|
|
finchar = 0;
|
|
|
|
outpos = 0;
|
2002-11-28 14:39:47 +05:30
|
|
|
posbits = 0 << 3;
|
2002-05-20 00:30:14 +05:30
|
|
|
|
2002-11-28 14:39:47 +05:30
|
|
|
free_ent = ((block_mode) ? FIRST : 256);
|
2002-05-20 00:30:14 +05:30
|
|
|
|
2002-11-28 14:39:47 +05:30
|
|
|
/* As above, initialize the first 256 entries in the table. */
|
2007-06-10 20:38:44 +05:30
|
|
|
/*clear_tab_prefixof(); - done by xzalloc */
|
2002-05-20 00:30:14 +05:30
|
|
|
|
2012-12-05 05:34:54 +05:30
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 255; i >= 0; --i)
|
|
|
|
tab_suffixof(i) = (unsigned char) i;
|
2002-11-28 14:39:47 +05:30
|
|
|
}
|
2002-05-20 00:30:14 +05:30
|
|
|
|
2002-11-28 14:39:47 +05:30
|
|
|
do {
|
2007-01-06 01:19:02 +05:30
|
|
|
resetbuf:
|
2002-05-20 00:30:14 +05:30
|
|
|
{
|
2002-11-28 14:39:47 +05:30
|
|
|
int i;
|
|
|
|
int e;
|
|
|
|
int o;
|
2002-05-20 00:30:14 +05:30
|
|
|
|
2007-01-06 01:19:02 +05:30
|
|
|
o = posbits >> 3;
|
|
|
|
e = insize - o;
|
2002-05-20 00:30:14 +05:30
|
|
|
|
2002-11-28 14:39:47 +05:30
|
|
|
for (i = 0; i < e; ++i)
|
|
|
|
inbuf[i] = inbuf[i + o];
|
2002-05-20 00:30:14 +05:30
|
|
|
|
|
|
|
insize = e;
|
|
|
|
posbits = 0;
|
|
|
|
}
|
|
|
|
|
2006-09-06 20:58:32 +05:30
|
|
|
if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) {
|
2014-12-07 05:14:00 +05:30
|
|
|
rsize = safe_read(xstate->src_fd, inbuf + insize, IBUFSIZ);
|
2011-08-18 17:59:41 +05:30
|
|
|
if (rsize < 0)
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg_and_die(bb_msg_read_error);
|
2002-05-20 00:30:14 +05:30
|
|
|
insize += rsize;
|
|
|
|
}
|
|
|
|
|
2002-11-28 14:39:47 +05:30
|
|
|
inbits = ((rsize > 0) ? (insize - insize % n_bits) << 3 :
|
|
|
|
(insize << 3) - (n_bits - 1));
|
2002-05-20 00:30:14 +05:30
|
|
|
|
2002-11-28 14:39:47 +05:30
|
|
|
while (inbits > posbits) {
|
2012-12-05 05:34:54 +05:30
|
|
|
long code;
|
|
|
|
|
2002-11-28 14:39:47 +05:30
|
|
|
if (free_ent > maxcode) {
|
|
|
|
posbits =
|
|
|
|
((posbits - 1) +
|
|
|
|
((n_bits << 3) -
|
|
|
|
(posbits - 1 + (n_bits << 3)) % (n_bits << 3)));
|
2002-05-20 00:30:14 +05:30
|
|
|
++n_bits;
|
2002-11-28 14:39:47 +05:30
|
|
|
if (n_bits == maxbits) {
|
2002-05-20 00:30:14 +05:30
|
|
|
maxcode = maxmaxcode;
|
2002-11-28 14:39:47 +05:30
|
|
|
} else {
|
|
|
|
maxcode = MAXCODE(n_bits) - 1;
|
|
|
|
}
|
|
|
|
bitmask = (1 << n_bits) - 1;
|
2002-05-20 00:30:14 +05:30
|
|
|
goto resetbuf;
|
|
|
|
}
|
2002-11-28 14:39:47 +05:30
|
|
|
{
|
|
|
|
unsigned char *p = &inbuf[posbits >> 3];
|
2012-12-05 05:34:54 +05:30
|
|
|
code = ((p[0]
|
|
|
|
| ((long) (p[1]) << 8)
|
|
|
|
| ((long) (p[2]) << 16)) >> (posbits & 0x7)) & bitmask;
|
2002-05-20 00:30:14 +05:30
|
|
|
}
|
|
|
|
posbits += n_bits;
|
|
|
|
|
2002-11-28 14:39:47 +05:30
|
|
|
if (oldcode == -1) {
|
2011-08-18 17:59:41 +05:30
|
|
|
if (code >= 256)
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg_and_die("corrupted data"); /* %ld", code); */
|
2006-10-01 21:25:11 +05:30
|
|
|
oldcode = code;
|
|
|
|
finchar = (int) oldcode;
|
|
|
|
outbuf[outpos++] = (unsigned char) finchar;
|
2002-05-20 00:30:14 +05:30
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-11-28 14:39:47 +05:30
|
|
|
if (code == CLEAR && block_mode) {
|
2002-05-20 00:30:14 +05:30
|
|
|
clear_tab_prefixof();
|
2002-11-28 14:39:47 +05:30
|
|
|
free_ent = FIRST - 1;
|
|
|
|
posbits =
|
|
|
|
((posbits - 1) +
|
|
|
|
((n_bits << 3) -
|
|
|
|
(posbits - 1 + (n_bits << 3)) % (n_bits << 3)));
|
2007-01-06 01:19:02 +05:30
|
|
|
n_bits = INIT_BITS;
|
|
|
|
maxcode = MAXCODE(INIT_BITS) - 1;
|
|
|
|
bitmask = (1 << INIT_BITS) - 1;
|
2002-05-20 00:30:14 +05:30
|
|
|
goto resetbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
incode = code;
|
2002-11-28 14:39:47 +05:30
|
|
|
stackp = de_stack;
|
2002-05-20 00:30:14 +05:30
|
|
|
|
2002-11-28 14:39:47 +05:30
|
|
|
/* Special case for KwKwK string. */
|
|
|
|
if (code >= free_ent) {
|
|
|
|
if (code > free_ent) {
|
2012-12-05 15:38:30 +05:30
|
|
|
/*
|
2002-11-28 14:39:47 +05:30
|
|
|
unsigned char *p;
|
2002-05-20 00:30:14 +05:30
|
|
|
|
|
|
|
posbits -= n_bits;
|
2002-11-28 14:39:47 +05:30
|
|
|
p = &inbuf[posbits >> 3];
|
2003-03-19 14:43:01 +05:30
|
|
|
bb_error_msg
|
2002-11-28 14:39:47 +05:30
|
|
|
("insize:%d posbits:%d inbuf:%02X %02X %02X %02X %02X (%d)",
|
2013-01-14 20:27:44 +05:30
|
|
|
insize, posbits, p[-1], p[0], p[1], p[2], p[3],
|
|
|
|
(posbits & 07));
|
2012-12-05 05:36:05 +05:30
|
|
|
*/
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg("corrupted data");
|
2007-06-10 20:38:44 +05:30
|
|
|
goto err;
|
2002-05-20 00:30:14 +05:30
|
|
|
}
|
|
|
|
|
2002-11-28 14:39:47 +05:30
|
|
|
*--stackp = (unsigned char) finchar;
|
|
|
|
code = oldcode;
|
2002-05-20 00:30:14 +05:30
|
|
|
}
|
|
|
|
|
2002-11-28 14:39:47 +05:30
|
|
|
/* Generate output characters in reverse order */
|
2012-12-05 05:34:54 +05:30
|
|
|
while (code >= 256) {
|
2011-08-18 17:59:41 +05:30
|
|
|
if (stackp <= &htabof(0))
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg_and_die("corrupted data");
|
2002-11-28 14:39:47 +05:30
|
|
|
*--stackp = tab_suffixof(code);
|
|
|
|
code = tab_prefixof(code);
|
2002-05-20 00:30:14 +05:30
|
|
|
}
|
|
|
|
|
2007-01-06 01:19:02 +05:30
|
|
|
finchar = tab_suffixof(code);
|
|
|
|
*--stackp = (unsigned char) finchar;
|
2002-05-20 00:30:14 +05:30
|
|
|
|
2002-11-28 14:39:47 +05:30
|
|
|
/* And put them out in forward order */
|
2002-05-20 00:30:14 +05:30
|
|
|
{
|
2002-11-28 14:39:47 +05:30
|
|
|
int i;
|
2002-05-20 00:30:14 +05:30
|
|
|
|
2007-01-06 01:19:02 +05:30
|
|
|
i = de_stack - stackp;
|
|
|
|
if (outpos + i >= OBUFSIZ) {
|
2002-11-28 14:39:47 +05:30
|
|
|
do {
|
|
|
|
if (i > OBUFSIZ - outpos) {
|
|
|
|
i = OBUFSIZ - outpos;
|
|
|
|
}
|
2002-05-20 00:30:14 +05:30
|
|
|
|
2002-11-28 14:39:47 +05:30
|
|
|
if (i > 0) {
|
|
|
|
memcpy(outbuf + outpos, stackp, i);
|
2002-05-20 00:30:14 +05:30
|
|
|
outpos += i;
|
|
|
|
}
|
|
|
|
|
2002-11-28 14:39:47 +05:30
|
|
|
if (outpos >= OBUFSIZ) {
|
2014-12-07 05:14:00 +05:30
|
|
|
xtransformer_write(xstate, outbuf, outpos);
|
2009-04-21 16:39:40 +05:30
|
|
|
IF_DESKTOP(total_written += outpos;)
|
2002-05-20 00:30:14 +05:30
|
|
|
outpos = 0;
|
|
|
|
}
|
2002-11-28 14:39:47 +05:30
|
|
|
stackp += i;
|
2007-01-06 01:19:02 +05:30
|
|
|
i = de_stack - stackp;
|
|
|
|
} while (i > 0);
|
2002-11-28 14:39:47 +05:30
|
|
|
} else {
|
|
|
|
memcpy(outbuf + outpos, stackp, i);
|
2002-05-20 00:30:14 +05:30
|
|
|
outpos += i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-28 14:39:47 +05:30
|
|
|
/* Generate the new entry. */
|
2012-12-05 05:34:54 +05:30
|
|
|
if (free_ent < maxmaxcode) {
|
|
|
|
tab_prefixof(free_ent) = (unsigned short) oldcode;
|
|
|
|
tab_suffixof(free_ent) = (unsigned char) finchar;
|
|
|
|
free_ent++;
|
2002-11-28 14:39:47 +05:30
|
|
|
}
|
2002-05-20 00:30:14 +05:30
|
|
|
|
2002-11-28 14:39:47 +05:30
|
|
|
/* Remember previous code. */
|
|
|
|
oldcode = incode;
|
2002-05-20 00:30:14 +05:30
|
|
|
}
|
2002-11-28 14:39:47 +05:30
|
|
|
} while (rsize > 0);
|
2002-05-20 00:30:14 +05:30
|
|
|
|
2002-09-27 12:16:02 +05:30
|
|
|
if (outpos > 0) {
|
2014-12-07 05:14:00 +05:30
|
|
|
xtransformer_write(xstate, outbuf, outpos);
|
2009-04-21 16:39:40 +05:30
|
|
|
IF_DESKTOP(total_written += outpos;)
|
2002-09-27 12:16:02 +05:30
|
|
|
}
|
2002-05-20 00:30:14 +05:30
|
|
|
|
2009-04-21 16:39:40 +05:30
|
|
|
retval = IF_DESKTOP(total_written) + 0;
|
2007-06-10 20:38:44 +05:30
|
|
|
err:
|
|
|
|
free(inbuf);
|
|
|
|
free(outbuf);
|
|
|
|
free(htab);
|
|
|
|
free(codetab);
|
|
|
|
return retval;
|
2002-05-20 00:30:14 +05:30
|
|
|
}
|