[SOLVED] C code review, too much error checking, is it handled well?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hmm.. I think of it like... it's not detected because it hasn't happened. The program for some reason encountered a string that was longer than the destination array,
I mean, the buffer overrun has already happened. If you are find the string is longer than the array, then you've written past the end (the only way to avoid writing past the end is to truncate the string: then the string wouldn't be longer than the array). It's true that if you make it into the bufck function and detect the overrun, that you are avoiding a segfault or worse.
Okay, interesting. I was thinking about suggesting a safer API (e.g., see http://www.and.org/vstr/comparison and http://www.and.org/vstr/security), but on the other hand, if most of your string manipulation is just reading and writing fixed-length strings like timestamps it might not be worth the trouble.
I didn't actually understand this completely - what other types of strings are there besides "fixed-length"? To my thinking, all strings are fixed length as they have to have memory allocated by using [x] or malloc/calloc, etc. ?
Quote:
Originally Posted by NevemTeve
Maybe it would be more robust if you stored unix-timestamp instead of just day-of-month. (Or you could go for human-readable timestamp (strftime("%Y%m%d%H%M%S")), but then you have to choose from UTC/localtime. I'd suggest UTC.)
I've switched to using the value returned by time(NULL). Seems like that should accomplish what you're suggesting, right?
I didn't actually understand this completely - what other types of strings are there besides "fixed-length"? To my thinking, all strings are fixed length as they have to have memory allocated by using [x] or malloc/calloc, etc. ?
I mean strings where you know the (maximum) length at compile time, so you don't have to use malloc/calloc.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.