-
Notifications
You must be signed in to change notification settings - Fork 3
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
various issues cancel found in the c version, some of which pose security risks #6
Comments
Or just use |
Thanks for the note, fao. You're right. Hmm.. they seem to recommend rsize_t for a lot of cases, what's size_t for now? The only thing I can think of that they didn't give to rsize_t is, converting to and from pointers? Is that what it's for? Looking back at the definition of Term_t, I'm not sure what I was thinking. I wanted them to be small but I also went with a ridiculous structpacking because I wanted the type tag to be at the front for some reason??? |
So I dug around: I was going to say something here, but at the last moment I got the impulse to double check, and quickly found this. So it looks like the correct type for that would be
Mm, I think I've seen some LISP implementations that use tags, the type tag at the front I think is a shorthand for allowing you to access the first element of the struct by casting the pointer to that type and referencing it. It's a little weird, IMHO, but it's not completely ridiculous :) |
So, weird. Maybe something was just wrong with size_t and they don't recommend it for anything any more.
Yeah.. I feel like I've seen that before as well. I wonder if rsize_t and intptr_t aren't coercible to each other, it sounds like they shouldn't be. That might be the benefit. Hmm, no, looking into it, rsize_t is just a typedef, so no coercion protection. It also doesn't look like it's in the C++ standard? And the bounds checking associated with rsize_t only happens if you consciously use _s functions? https://en.cppreference.com/w/c/error
Hm, I'm convinced. I remember bringing this up with cancel ("Eskil Steenburg themself said that a pointer to a struct is always a pointer to its first element!") and apparently it's not in the C standards, but every relevant compiler does it and (clearly) so many users depend on it, I guess it's a de-facto standard behaviour at this point. |
Ah, yeah so. A little more digging suggests that indeed that purpose of
I mean, semantically I can't think of an instance where you would want to coerce the one to the other unless you're doing
C++ and C are different languages :) Especially when you hit Actually, while double checking I was correct on the above, I stumbled upon this SO thread you might find useful. It quotes the standard on the rationale of
The C11 standard seems to guarantee this. I dunno if it's guaranteed in earlier standards or specific to C11, though. |
Generally, the more specific we are about types, the more 'you put that into the wrong slot' errors we can spot, but, yeah, for that to do any good I think there would have to exist some function call that wants both a rsize_t and an intptr_t that a programmer could potentially get mixed up, and I can't think of any examples of that either (although that's not an API space I'd expect myself to know well) Currently the code compiles under C and C++ mode, it would be convenient to keep it that way
Ah yep. Turns out Cancel was talking about C++ standards back then. |
restrict
for stringsThe text was updated successfully, but these errors were encountered: