icetime: never silently truncate asc file lines

icetime was reading the asc configuration file using a 128-byte line
buffer -- which is usually fine, but can cause it to truncate the names
of nets given in .sym lines if those names are very, very long.  The way
fgets was being used meant this went undetected.

Long net names like this can arise in deeply hierarchical designs,
particularly if there's a code generator involved.

This change:
1. Increases the buffer size to 64kiB.
2. Adds a truncation check that causes icetime to fail.

A more robust solution would manage the line buffer on the heap, since
the symbol gets copied into a std::string anyway, but this is a
workaround for now.
This commit is contained in:
Cliff L. Biffle 2017-05-09 08:06:43 -07:00
parent 0f64fdf573
commit e787fa2d30
1 changed files with 10 additions and 2 deletions

View File

@ -208,11 +208,19 @@ void read_pcf(const char *filename)
void read_config()
{
char buffer[128];
constexpr size_t line_buf_size = 65536;
char buffer[line_buf_size];
int tile_x, tile_y, line_nr = -1;
while (fgets(buffer, 128, fin))
while (fgets(buffer, line_buf_size, fin))
{
if (buffer[strlen(buffer) - 1] != '\n')
{
fprintf(stderr, "Input file contains very long lines.\n");
fprintf(stderr, "icetime cannot process it.\n");
exit(1);
}
if (buffer[0] == '.')
{
line_nr = -1;