Why does this return no warnings? What is supposed to be wrong with the code?
char *str = malloc(strlen("hello" + 1));
strcpy(str, "hello");
Thanks!
Why would you expect warnings?
The code is broken because you should be doing strlen("hello") + 1
, not strlen("hello" + 1)
(which is equivalent to strlen("ello")
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With