Closed tiras-j closed 8 years ago
Haha yes that is a really silly issue, I increased all the struct array sizes recently but I must have missed the string. I also have not yet implemented the finer error checking, I was too busy obsessing over posix threads and fun stuff like that :-)
Thanks for bringing up mmap, I had actually never heard of it! I'll see if that would work for me. And I definitely recommend writing your own interpreter, I've been having a lot of fun with this one!
I upped the string size but I found that if I set it too high it caused segfault which is a little strange. I think the better solution anyway is to some other strategy for opening files like mmap.
Hmm... It's interesting that a stack allocated array would cause a segfault like that, unless perhaps your overflowing the default stack size.
But definitely either malloc'ing some space and copying the file in (as you're currently doing, just with heap allocated memory) or mmap'ing would give you the same indexable behavior that I'm guessing the lexer expects. mmap is more efficient but might be less portable if either of those are concerns.
Anyways good luck! You've inspired me to build an interpreter to play around with. Maybe I'll finally make a Show HN post some day haha.
Fixed by @TheLoneWolfling
I might be losing my mind but isn't your struct String defined to allocate 256 characters of space as per:
However when you read the target file into a stack allocated String struct in huo.c there is no check against the number of characters read:
Out of curiosity, why not just mmap the file and then you can index into it? Anyways I may be missing something completely obvious here, it's a bit late.
Also this is awesome, I've been toying with the idea of making a small compiled language to play around with LLVM but maybe an interpreter would be more fun to play around with :)