Large program files and/or tight memory constraints can cause segfaults during program buffering. Expected: An exit with an error message.
A sparse file containing a LOLCODE program and trailing NULs will usually run correctly. For example, the following set of commands creates a sparse 1MB file (using something like 4kB on disk) and runs it.
From what I can tell, two issues contribute to this behavior.
The variable size is declared as unsigned int instead of as size_t. This makes it wrap around at 232 on most systems, even when more than 4GB of RAM is available. At that point, realloc is asked to resize the buffer to 0 bytes.
The return value of realloc isn't checked. If the reallocation is unsuccessful, buffer is replaced with a null pointer.
If you're testing this on your own machine, you may want to limit the memory usage to avoid thrashing. I ran ulimit -v 6291456 to enforce a hard 6GB limit.
Large program files and/or tight memory constraints can cause segfaults during program buffering. Expected: An exit with an error message.
A sparse file containing a LOLCODE program and trailing NULs will usually run correctly. For example, the following set of commands creates a sparse 1MB file (using something like 4kB on disk) and runs it.
However, making the file 1TB causes
lci
to segfault.Here's the variable that keeps track of the buffer size. https://github.com/justinmeza/lci/blob/6762b724361a4fb471345961b4750657783aeb3b/main.c#L144 And here's the loop that reads the input file. https://github.com/justinmeza/lci/blob/6762b724361a4fb471345961b4750657783aeb3b/main.c#L193-L200
From what I can tell, two issues contribute to this behavior.
size
is declared asunsigned int
instead of assize_t
. This makes it wrap around at 232 on most systems, even when more than 4GB of RAM is available. At that point,realloc
is asked to resize the buffer to 0 bytes.realloc
isn't checked. If the reallocation is unsuccessful,buffer
is replaced with a null pointer.If you're testing this on your own machine, you may want to limit the memory usage to avoid thrashing. I ran
ulimit -v 6291456
to enforce a hard 6GB limit.