Skip to content
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

tests/example segfaults on add user #228

Closed
wittend opened this issue Mar 10, 2021 · 6 comments
Closed

tests/example segfaults on add user #228

wittend opened this issue Mar 10, 2021 · 6 comments

Comments

@wittend
Copy link

wittend commented Mar 10, 2021

On Ubuntu 18.04 example segfaults on option 1 or 2

$ git clone
$ cd uthash/tests

$ make
all tests pass

$ make clean
$ make example
cc -I../src -g -Wall -o example example.c
(warnings concerning gets, add_user, atoi...)

$.../uthash/tests$ ./example

  1. add user
  2. add/rename user by id
  3. find user
  4. delete user
  5. delete all users
  6. sort items by name
  7. sort items by id
  8. print users
  9. count users
  10. quit
    1
    name?
    Gertrude
    Segmentation fault (core dumped)

Option 2 behaves similarly.

@Quuxplusone
Copy link
Collaborator

Quuxplusone commented Mar 10, 2021

Hm. Can't reproduce on RHEL5 or Mac OSX. It would be useful to see (1) a transcript of exactly what you entered (e.g. if it wasn't Gertrude but maybe Gertrude-followed-by-several-space-characters?), and/or (2) a stack trace. Obviously example.c isn't "safe," in the sense that it does a gets into a 10-byte buffer, so if you overflow the buffer all bets are off.

Oh, and if changing the buffer size from [10] to [100] fixes your segfault, that's useful to know too.

@wittend
Copy link
Author

wittend commented Mar 10, 2021 via email

@wittend
Copy link
Author

wittend commented Mar 10, 2021 via email

@pdebuyl
Copy link

pdebuyl commented Apr 27, 2021

Hi @Quuxplusone are you interested in a pull request for this?

gets() is not recommended, so it could be useful to fix this.

I am using uthash since a few weeks and find it very useful, so I would be willing to propose something according to your criteria.

@Quuxplusone
Copy link
Collaborator

@pdebuyl: Sure, if you want to make a PR, I'll look at it. No promises, though. I wouldn't like to complicate the example code too much; I agree it's really bad that it currently relies on gets, but I've also already looked at the naïve "rewrite to use fgets" version and it looked a lot uglier.

It might even be better to throw out the example code and write a completely different example program without gets or fgets, as long as it was something interactive that exercised all the same API entry points.

@Quuxplusone
Copy link
Collaborator

Fixed by a109c6b !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants