FlintPlusPlus icon indicating copy to clipboard operation
FlintPlusPlus copied to clipboard

error in Tokenizer.cpp:99

Open dribbroc opened this issue 9 years ago • 5 comments

Running flint++ from master (c04020e8693b315) on my own code results in

flint++: Tokenizer.cpp:99: std::string flint::{anonymous}::munchSingleLineComment(std::string&, size_t&): Assertion `i < pc.size()' failed.

Program received signal SIGABRT, Aborted. 0x00007ffff75390d5 in __GI_raise (sig=) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64 64 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory. (gdb) bt #0 0x00007ffff75390d5 in __GI_raise (sig=) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64 #1 0x00007ffff753c83b in __GI_abort () at abort.c:91 #2 0x00007ffff7531d9e in __assert_fail_base (fmt=, assertion=0x422b70 "i < pc.size()", file=0x4224ea "Tokenizer.cpp", line=, function=) at assert.c:94 #3 0x00007ffff7531e42 in __GI___assert_fail (assertion=0x422b70 "i < pc.size()", file=0x4224ea "Tokenizer.cpp", line=99,

function=0x423460 "std::string flint::{anonymous}::munchSingleLineComment(std::string&, size_t&)") at assert.c:103

#4 0x000000000041f7be in flint::tokenize(std::string const&, std::string const&, std::vector<flint::Token, std::allocatorflint::Token >&) () #5 0x0000000000413b2c in checkEntry(flint::ErrorReport&, std::string const&, unsigned int) () #6 0x00000000004140f6 in checkEntry(flint::ErrorReport&, std::string const&, unsigned int) () #7 0x00000000004140f6 in checkEntry(flint::ErrorReport&, std::string const&, unsigned int) () #8 0x0000000000402f7e in main ()

dribbroc avatar Jan 22 '16 12:01 dribbroc

AFAIK this happens when comment has length of 2, i.e. nothing goes after // I have a sample file to reproduce this issue. But this assert is commented in the source version, so I think binaries should be updated

alariq avatar Mar 15 '16 13:03 alariq

I couldn't replicate in my fork - added empty comments to the test suite - 8ffd893. Please provide minimal working example here or as a new ticket on mine.

AaronDMarasco avatar Jun 14 '20 11:06 AaronDMarasco

I've got the same issue. In my case, there is a comment with // at the end of the file and there is no ending line. Ex: image To fix the issue, I just need to add an extra line below the comment image

lengocthuong15 avatar Jan 19 '21 08:01 lengocthuong15

@lengocthuong15 please try my fork at https://github.com/AaronDMarasco/FlintPlusPlus - this fork has been untouched for about six years now. I've added RPM, DEB, Docker, etc too.

I have a file that specifically doesn't have a newline at the end (within a comment) as part of the test suite - https://github.com/AaronDMarasco/FlintPlusPlus/blob/master/flint/tests/Comments.cpp

Original:

❯ xxd Comments.cpp | tail
000001a0: 7369 7665 2e0a 2320 2f2f 2049 7427 7320  sive..# // It's 
000001b0: 6e6f 7420 616e 2075 6e74 6572 6d69 6e61  not an untermina
000001c0: 7465 6420 7374 7269 6e67 2e0a 2320 2f2f  ted string..# //
000001d0: 204e 6569 7468 6572 2069 7320 2274 6869   Neither is "thi
000001e0: 732e 0a0a 2f2f 2045 6d70 7479 2063 6f6d  s...// Empty com
000001f0: 6d65 6e74 3a0a 2f2f 0a2f 2a2a 2f0a 2f2f  ment:.//./**/.//
00000200: 2050 6172 7469 6375 6c61 726c 7920 6e61   Particularly na
00000210: 7374 7920 656d 7074 7920 636f 6d6d 656e  sty empty commen
00000220: 7420 7769 7468 206e 6f20 6e65 776c 696e  t with no newlin
00000230: 652c 206a 7573 7420 454f 463a 0a2f 2f    e, just EOF:.//

I tried to emulate your problem and it passed all checks:

❯ xxd Comments.cpp | tail
000001c0: 7465 6420 7374 7269 6e67 2e0a 2320 2f2f  ted string..# //
000001d0: 204e 6569 7468 6572 2069 7320 2274 6869   Neither is "thi
000001e0: 732e 0a0a 2f2f 2045 6d70 7479 2063 6f6d  s...// Empty com
000001f0: 6d65 6e74 3a0a 2f2f 0a2f 2a2a 2f0a 2f2f  ment:.//./**/.//
00000200: 2050 6172 7469 6375 6c61 726c 7920 6e61   Particularly na
00000210: 7374 7920 656d 7074 7920 636f 6d6d 656e  sty empty commen
00000220: 7420 7769 7468 206e 6f20 6e65 776c 696e  t with no newlin
00000230: 652c 206a 7573 7420 454f 463a 0a2f 2f20  e, just EOF:.// 
00000240: 6120 636f 6d6d 656e 7420 6174 2074 6865  a comment at the
00000250: 2065 6e64 206f 6620 7468 6520 6669 6c65   end of the file

AaronDMarasco avatar Jan 20 '21 00:01 AaronDMarasco

Thank @AaronDMarasco

lengocthuong15 avatar Jan 20 '21 01:01 lengocthuong15