X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Flexer%2Flexer.c;h=8d2468ab7bb31aae1e13e1eff902f0a2b88daa9f;hb=29a50aeb6f35214d2affdec3bdb796f2d0e655ba;hp=47808898abe1b4f2c8a1a97e35d93d4f55ba7755;hpb=8f20801a82fe1382da0033996c08160a9f93a3da;p=pspp diff --git a/src/language/lexer/lexer.c b/src/language/lexer/lexer.c index 47808898ab..8d2468ab7b 100644 --- a/src/language/lexer/lexer.c +++ b/src/language/lexer/lexer.c @@ -1231,7 +1231,10 @@ lex_ellipsize__ (struct substring in, char *out, size_t out_size) 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' @@ -1243,6 +1246,10 @@ lex_ellipsize__ (struct substring in, char *out, size_t out_size) 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; } @@ -1435,13 +1442,9 @@ lex_source_get__ (const struct lex_source *src_) 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))); src->journal_pos += line_len; }