Skip to content
Snippets Groups Projects
Commit 32e743bb authored by Niels Möller's avatar Niels Möller
Browse files

(sexp_put_string): Fixed handling of escapable

characters. The code generated random escape sequences for
characters in the 0x10-0x1f range.

Rev: src/nettle/tools/output.c:1.2
parent bf8ba3ce
No related branches found
No related tags found
No related merge requests found
...@@ -176,8 +176,12 @@ sexp_put_string(struct sexp_output *output, enum sexp_mode mode, ...@@ -176,8 +176,12 @@ sexp_put_string(struct sexp_output *output, enum sexp_mode mode,
unsigned i; unsigned i;
int token = (string->contents[0] < '0' || string->contents[0] > '9'); int token = (string->contents[0] < '0' || string->contents[0] > '9');
int quote_friendly = 1; int quote_friendly = 1;
static const char escape_names[0x10] = #define CONTROL_SIZE 0x20
{ 0,0,0,0,0,0,0,0, 'b','t','n',0,'f','r',0,0 }; static const char escape_names[CONTROL_SIZE] =
{
0,0,0,0,0,0,0,0, 'b','t','n',0,'f','r',0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0
};
for (i = 0; i<string->size; i++) for (i = 0; i<string->size; i++)
{ {
...@@ -190,7 +194,7 @@ sexp_put_string(struct sexp_output *output, enum sexp_mode mode, ...@@ -190,7 +194,7 @@ sexp_put_string(struct sexp_output *output, enum sexp_mode mode,
{ {
if (c >= 0x7f) if (c >= 0x7f)
quote_friendly = 0; quote_friendly = 0;
else if (c < 0x20 && !escape_names[c]) else if (c < CONTROL_SIZE && !escape_names[c])
quote_friendly = 0; quote_friendly = 0;
} }
} }
...@@ -211,7 +215,7 @@ sexp_put_string(struct sexp_output *output, enum sexp_mode mode, ...@@ -211,7 +215,7 @@ sexp_put_string(struct sexp_output *output, enum sexp_mode mode,
if (c == '\\' || c == '"') if (c == '\\' || c == '"')
escape = 1; escape = 1;
else if (c < 0x20) else if (c < CONTROL_SIZE)
{ {
escape = 1; escape = 1;
c = escape_names[c]; c = escape_names[c];
...@@ -247,6 +251,7 @@ sexp_put_string(struct sexp_output *output, enum sexp_mode mode, ...@@ -247,6 +251,7 @@ sexp_put_string(struct sexp_output *output, enum sexp_mode mode,
sexp_put_code_end(output); sexp_put_code_end(output);
sexp_put_char(output, delimiter); sexp_put_char(output, delimiter);
} }
#undef CONTROL_SIZE
} }
else else
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment