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.
In the following code, the minimum size for cOut is 25 as seen. However, the length of cOut by the time this code is run is 17, which would make me think that the minimum size for cOut should be 18. Anything lower than 25 causes a segmentation fault. Does the function strcat need some extra elements in the string for intermediate operations or something?
char * cOut[25] is an array-of-ptrs-to char (25 to be exact)
char cOut[25] is an array-of-char (25 'slots' long) aka a c 'string' if you terminate correctly (ie '\0')
iirc, if you initialise a ptr-to-char during a declaration, that makes it a constant ?
It's been a while and I don't have my books handy.
Whats that line for? iRight has been given a string value immediately before, yet your trying to convert it to a string? (sprintf can not know that iRight is not a number, since you told it to expect a number, it will interpret the pointer as a number). There is also no garentee that the output will be 4 chars (for a total of 5 in the string). This leads to memory corruption in the surrounding data, which can easily lead to messed-up data that will cause a segfault.
Your using unsafe functions, in a unsafe mannor, and the requirement of no-less then 25 for the size is probably due to the program corrupting itself, and with a value of 25 it simply has more room to corrupt itself before it starts overriding memory that will cause a segfault.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.