4 ms·
I'm quite new to C programming. What's wrong with doing those things?
by __rkaup__ 15y ago
I'm quite new to C programming. What's wrong with doing those things?
- fleitz 15y ago"malloc(size+1)" is a sign you may have one off errors in your code. If you need to store a string of size s you need s+1 bytes allocated. The plus one is for null termination. If you want an array of t you can either pass the size around with the array or null terminate the array like strings, but then you can't store any null values in the array. Also, there's no bounds checking on size so in certain conditions such as a 2GB/4GB allocation you may allocate zero bytes or -2GB bytes.
- tptacek 15y agoNumbers can't grow indefinitely; they wrap (usually at the size of the register).