New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using strncpy
to copy overlapping strings.
#2
Comments
Oh, that Mac makefile shouldn't be there. I was experimenting with the build but always faced the same issue of the segfault on start. I figured I'd done something wrong with it and meant to remove it. Is the STRNCPY you've pointed out the source of this abort? The i18n.c file has been used in a couple of other projects and hasn't crashed there (valgrind doesn't report an issue either): https://github.com/stephenjsweeney/tbftss/blob/master/src/system/i18n.c https://github.com/riksweeney/edgar/blob/master/src/i18n.c Maybe scrap the make file and start over, in case it's actually the source of the issue. |
Possibly. I know when I change your STRNCPY macro to use memmove the game starts up, although only when I run it in lldb. (Which makes it difficult to debug. :( ). But ya, here is the stack trace lldb gives me:
Which corresponds to that block of code. I'll investigate further. |
Please try the latest code in the develop branch (includes some other bug fixes). This should get past the i18n.c string smashing. There might be others, but hopefully not. |
Cool, it seems to start up for me now. :D |
(although I should mention that full screen is not yet working.) |
Fullscreen requires you to exit and restart the game (unless you've done that and it still doesn't work?) |
Ah, okay. Well in that case it works. Thanks. :) |
Your
STRNCPY
macro (which just seems to call strncpy and then manually set the last byte to null), seems to frequently copy overlapping strings.For example, in
src/system/i18n.c
, line 78, you have:The use of
strtok
andstrncpy
seem to imply that thelang
andlanguage
buffers overlap. Which, per the man page (and c spec) is undefined, and frequently causes segfaults:If you want to copy to buffers that overlap, you either need to do it manually, or use functions like
memmove
(note thatmemcpy
has the same problem).As is, this currently causes builds to call SIGABRT on os x (10.11, using clang).
I built the game with:
The text was updated successfully, but these errors were encountered: