/* Prints a syntax error message saying that OPTION0 or one of the other
strings following it, up to the first NULL, is expected. */
void
-lex_error_expecting (struct lexer *lexer, const char *option0, ...)
+(lex_error_expecting) (struct lexer *lexer, const char *option0, ...)
{
enum { MAX_OPTIONS = 8 };
const char *options[MAX_OPTIONS + 1];
return true;
else
{
- lex_error_expecting (lexer, identifier, NULL_SENTINEL);
+ lex_error_expecting (lexer, identifier);
return false;
}
}
if (type_string)
{
char *s = xasprintf ("`%s'", type_string);
- lex_error_expecting (lexer, s, NULL_SENTINEL);
+ lex_error_expecting (lexer, s);
free (s);
}
else
- lex_error_expecting (lexer, token_type_to_name (type), NULL_SENTINEL);
+ lex_error_expecting (lexer, token_type_to_name (type));
return false;
}
int mblen;
assert (out_size >= 16);
- out_maxlen = out_size - (in.length >= out_size ? 3 : 0) - 1;
+ out_maxlen = out_size - 1;
+ if (in.length > out_maxlen - 3)
+ out_maxlen -= 3;
+
for (out_len = 0; out_len < in.length; out_len += mblen)
{
if (in.string[out_len] == '\n'
mblen = u8_mblen (CHAR_CAST (const uint8_t *, in.string + out_len),
in.length - out_len);
+
+ if (mblen < 0)
+ break;
+
if (out_len + mblen > out_maxlen)
break;
}
if (copy_len > 0 && line[copy_len - 1] == '\r')
copy_len--;
- /* Make a copy of the line with \n end-of-line and null terminator. */
- char *syntax = xmalloc (copy_len + 2);
- memcpy (syntax, line, copy_len);
- syntax[copy_len] = '\n';
- syntax[copy_len + 1] = '\0';
-
- text_item_submit (text_item_create_nocopy (TEXT_ITEM_SYNTAX, syntax));
+ /* Submit the line as syntax. */
+ text_item_submit (text_item_create_nocopy (TEXT_ITEM_SYNTAX,
+ xmemdup0 (line, copy_len),
+ NULL));
src->journal_pos += line_len;
}