diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-01-27 12:06:47 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-01-27 12:09:36 -0700 |
| commit | fe0c6a3df9480cc3d0be7412cd24bba4366c18a1 (patch) | |
| tree | eabeaeb90961c4c7ad8abe40b85339ad4d4a281d /src/errmsg.cpp | |
| parent | fa1ea6062b172e75674353ee19857db9046ec9ee (diff) | |
| download | zig-fe0c6a3df9480cc3d0be7412cd24bba4366c18a1.tar.gz zig-fe0c6a3df9480cc3d0be7412cd24bba4366c18a1.zip | |
fix crash when compiling empty file
closes #90
Diffstat (limited to 'src/errmsg.cpp')
| -rw-r--r-- | src/errmsg.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/errmsg.cpp b/src/errmsg.cpp index 8780f33a52..e8ab353efc 100644 --- a/src/errmsg.cpp +++ b/src/errmsg.cpp @@ -80,9 +80,12 @@ ErrorMsg *err_msg_create_with_line(Buf *path, int line, int column, int line_start_offset = line_offsets->at(line); int end_line = line + 1; int line_end_offset = (end_line >= line_offsets->length) ? buf_len(source) : line_offsets->at(line + 1); + int len = line_end_offset - line_start_offset - 1; + if (len < 0) { + len = 0; + } - buf_init_from_mem(&err_msg->line_buf, buf_ptr(source) + line_start_offset, - line_end_offset - line_start_offset - 1); + buf_init_from_mem(&err_msg->line_buf, buf_ptr(source) + line_start_offset, len); return err_msg; } |
