aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2018-12-05 08:38:55 +0000
committerRon Yorston <rmy@pobox.com>2018-12-05 08:38:55 +0000
commit2a34d6d4e3122df2f84eb1290221128be47dc36b (patch)
treea7035842113f36823c4e7c16744416259f0a8bf6 /libbb
parent5448a3893434a64d184055be81a58f47ea6af51b (diff)
parentd08206dce1291f512d7de9037d9ef1ffbf705cac (diff)
downloadbusybox-w32-2a34d6d4e3122df2f84eb1290221128be47dc36b.tar.gz
busybox-w32-2a34d6d4e3122df2f84eb1290221128be47dc36b.tar.bz2
busybox-w32-2a34d6d4e3122df2f84eb1290221128be47dc36b.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'libbb')
-rw-r--r--libbb/print_numbered_lines.c10
-rw-r--r--libbb/process_escape_sequence.c16
2 files changed, 19 insertions, 7 deletions
diff --git a/libbb/print_numbered_lines.c b/libbb/print_numbered_lines.c
index 9a8a51440..d6459d7c3 100644
--- a/libbb/print_numbered_lines.c
+++ b/libbb/print_numbered_lines.c
@@ -8,12 +8,16 @@
8 8
9#include "libbb.h" 9#include "libbb.h"
10 10
11void FAST_FUNC print_numbered_lines(struct number_state *ns, const char *filename) 11int FAST_FUNC print_numbered_lines(struct number_state *ns, const char *filename)
12{ 12{
13 FILE *fp = fopen_or_warn_stdin(filename); 13 FILE *fp = fopen_or_warn_stdin(filename);
14 unsigned N = ns->start; 14 unsigned N;
15 char *line; 15 char *line;
16 16
17 if (!fp)
18 return EXIT_FAILURE;
19
20 N = ns->start;
17 while ((line = xmalloc_fgetline(fp)) != NULL) { 21 while ((line = xmalloc_fgetline(fp)) != NULL) {
18 if (ns->all 22 if (ns->all
19 || (ns->nonempty && line[0]) 23 || (ns->nonempty && line[0])
@@ -27,4 +31,6 @@ void FAST_FUNC print_numbered_lines(struct number_state *ns, const char *filenam
27 ns->start = N; 31 ns->start = N;
28 32
29 fclose(fp); 33 fclose(fp);
34
35 return EXIT_SUCCESS;
30} 36}
diff --git a/libbb/process_escape_sequence.c b/libbb/process_escape_sequence.c
index 59d0d3ea8..13022b83e 100644
--- a/libbb/process_escape_sequence.c
+++ b/libbb/process_escape_sequence.c
@@ -37,12 +37,18 @@ char FAST_FUNC bb_process_escape_sequence(const char **ptr)
37 * We treat \2 as a valid octal escape sequence. */ 37 * We treat \2 as a valid octal escape sequence. */
38 do { 38 do {
39 unsigned r; 39 unsigned r;
40#if !WANT_HEX_ESCAPES
41 unsigned d = (unsigned char)(*q) - '0'; 40 unsigned d = (unsigned char)(*q) - '0';
42#else 41#if WANT_HEX_ESCAPES
43 unsigned d = (unsigned char)_tolower(*q) - '0'; 42 if (d >= 10) {
44 if (d >= 10) 43 d = (unsigned char)_tolower(*q) - 'a';
45 d += ('0' - 'a' + 10); 44 //d += 10;
45 /* The above would map 'A'-'F' and 'a'-'f' to 10-15,
46 * however, some chars like '@' would map to 9 < base.
47 * Do not allow that, map invalid chars to N > base:
48 */
49 if ((int)d >= 0)
50 d += 10;
51 }
46#endif 52#endif
47 if (d >= base) { 53 if (d >= base) {
48 if (WANT_HEX_ESCAPES && base == 16) { 54 if (WANT_HEX_ESCAPES && base == 16) {