Allow hex escape sequences
This commit is contained in:
parent
ac594257c3
commit
53f5c0d5bf
@ -22,42 +22,35 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <ctype.h>
|
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
|
|
||||||
#define isodigit(c) ((c) >= '0' && (c) <= '7')
|
|
||||||
#define hextobin(c) ((c)>='a'&&(c)<='f' ? (c)-'a'+10 : (c)>='A'&&(c)<='F' ? (c)-'A'+10 : (c)-'0')
|
|
||||||
#define octtobin(c) ((c) - '0')
|
|
||||||
char bb_process_escape_sequence(const char **ptr)
|
char bb_process_escape_sequence(const char **ptr)
|
||||||
{
|
{
|
||||||
const char *p, *q;
|
|
||||||
unsigned int num_digits, r, n, hexescape;
|
|
||||||
static const char charmap[] = {
|
static const char charmap[] = {
|
||||||
'a', 'b', 'f', 'n', 'r', 't', 'v', '\\', 0,
|
'a', 'b', 'f', 'n', 'r', 't', 'v', '\\', 0,
|
||||||
'\a', '\b', '\f', '\n', '\r', '\t', '\v', '\\', '\\' };
|
'\a', '\b', '\f', '\n', '\r', '\t', '\v', '\\', '\\' };
|
||||||
|
|
||||||
n = r = hexescape = num_digits = 0;
|
const char *p;
|
||||||
|
const char *q;
|
||||||
|
unsigned int num_digits;
|
||||||
|
unsigned int r;
|
||||||
|
unsigned int n;
|
||||||
|
|
||||||
|
n = 0;
|
||||||
q = *ptr;
|
q = *ptr;
|
||||||
|
|
||||||
if (*q == 'x') {
|
num_digits = 0;
|
||||||
hexescape++;
|
|
||||||
++q;
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (hexescape && isxdigit(*q)) {
|
if (((unsigned int)(*q - '0')) <= 7) {
|
||||||
r = n * 16 + hextobin(*q);
|
r = n * 8 + (*q - '0');
|
||||||
} else if (isodigit(*q)) {
|
if (r <= UCHAR_MAX) {
|
||||||
r = n * 8 + octtobin(*q);
|
n = r;
|
||||||
}
|
++q;
|
||||||
if (r <= UCHAR_MAX) {
|
if (++num_digits < 3) {
|
||||||
n = r;
|
continue;
|
||||||
++q;
|
}
|
||||||
if (++num_digits < 3) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user