diff options
author | David Robillard <d@drobilla.net> | 2011-12-10 21:50:46 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-12-10 21:50:46 +0000 |
commit | 2f4cc718e4588701c02ab98beb17a1adc86431f8 (patch) | |
tree | 8d0a67097676462b1f187c103ba0bdf8160018e2 | |
parent | d1cb0f8e7269b45ad0422c29f4d6dceebeedc48e (diff) | |
download | serd-2f4cc718e4588701c02ab98beb17a1adc86431f8.tar.gz serd-2f4cc718e4588701c02ab98beb17a1adc86431f8.tar.bz2 serd-2f4cc718e4588701c02ab98beb17a1adc86431f8.zip |
Tolerate invalid characters in string literals by replacing with the
Unicode replacement character.
git-svn-id: http://svn.drobilla.net/serd/trunk@232 490d8e77-9747-427b-9fa3-0b8f29cee8a0
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | src/reader.c | 33 |
2 files changed, 30 insertions, 5 deletions
@@ -2,6 +2,8 @@ serd (UNRELEASED) unstable; urgency=low * Use path variables in pkgconfig files * Install man page to DATADIR (e.g. PREFIX/share/man, not PREFIX/man) + * Tolerate invalid characters in string literals by replacing with the + Unicode replacement character -- David Robillard <d@drobilla.net> (UNRELEASED) diff --git a/src/reader.c b/src/reader.c index 70bdd1a1..9059236f 100644 --- a/src/reader.c +++ b/src/reader.c @@ -96,13 +96,31 @@ struct SerdReaderImpl { }; static int +msg(SerdReader* reader, const char* prefix, const char* fmt, va_list args) +{ + fprintf(stderr, "%s: %s:%u:%u: ", + prefix, reader->cur.filename, reader->cur.line, reader->cur.col); + vfprintf(stderr, fmt, args); + return 0; +} + +static int error(SerdReader* reader, const char* fmt, ...) { va_list args; va_start(args, fmt); - fprintf(stderr, "error: %s:%u:%u: ", - reader->cur.filename, reader->cur.line, reader->cur.col); - vfprintf(stderr, fmt, args); + msg(reader, "error", fmt, args); + va_end(args); + return 0; +} + +static int +warn(SerdReader* reader, const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + msg(reader, "warning", fmt, args); + va_end(args); return 0; } @@ -493,8 +511,13 @@ read_character(SerdReader* reader, Ref dest) } else if ((c & 0xF8) == 0xF0) { // Starts with `11110' size = 4; } else { - error(reader, "invalid character\n"); - return SERD_ERR_BAD_SYNTAX; + warn(reader, "invalid character\n"); + // Push replacement character + push_byte(reader, dest, 0xEF); + push_byte(reader, dest, 0xBF); + push_byte(reader, dest, 0xBD); + eat_byte(reader, c); + return SERD_SUCCESS; } for (unsigned i = 0; i < size; ++i) { push_byte(reader, dest, eat_byte(reader, peek_byte(reader))); |