News for hackers. Stuff that matters.
Re:Massacring C Pointers by konstmonst on Tuesday June 26, 2018 @02:19AM (#17398294)
There are multiple problems with that code: 1) return(r) He is returning pointer to temporary! When you declare and initialize variables on stack after that function, they will overwrite memory pointed by r. 2) He is assuming size of string pointed by s(including 0) is less than 100 and also the combined sizes of s and t are less than 100. Stack Overflow! 3) Not an errors, but would not pass my code review: Inconsistent Variable declaration, using signed integer for loop where you don't need signed. Also I would have used strcpy 2 times, or loop 2 times, not two different ways. Beside that, you should not use strcpy, but strncpy to avoid stack overflows.
Re:Massacring C Pointers by saagarjha on Tuesday June 26, 2018 @02:32AM (#17398353)
> Inconsistent Variable declaration

How so?

> I would have used strcpy 2 times

You can't do this, because strcpy doesn't give you the length of the string you copied, which is necessary to put the trailing null byte.

Re:Massacring C Pointers by scatters on Tuesday June 26, 2018 @04:51AM (#17398888)
strcpy writes a trailing zero.

> The strcpy() function copies the string pointed to by src, including the terminating null byte ('\0'), to the buffer pointed to by dest.

Re:Massacring C Pointers by saagarjha on Wednesday June 27, 2018 @02:46AM (#17406219)
Yup, I'm aware of that, but the author of that code sure isn't ;)