Pregunta

char imei_temp[14] = {0, };

strcpy(imei_temp, "00000000000000");

According to my understanding this is valid code.

But Klocwork is saying Buffer overflow, array index of 'imei_temp' may be out of bounds. Array 'imei_temp' of size 14 may use index value(s) 0..14

¿Fue útil?

Solución

It's a buffer overflow because your buffer is 14 bytes, but you are writing 15 bytes to it: 14 ascii "0"'s, and a null byte at the end.

Otros consejos

when you specify a string using "s it adds an implicit \0 to the end of the string, you're trying to copy 15 bytes in to a 14 byte buffer.

Note, this doesn't happen when you specify a character using 's.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top