cppcheck 2.14 says:
tmp.c:10:12: warning: Uninitialized variable: buf [uninitvar]
return buf[n / 2];
^
tmp.c:6:18: note: Assuming condition is false
for(i = 0; i < n; i++)
^
tmp.c:10:12: note: Uninitialized variable: buf
return buf[n / 2];
^
However n is always at least 1, so the used part of the buf is always set.
I know, it requires global analysis :-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, it is dangerous to call GetValue(0), however this case will never happen. The function is static, so not callable from outside of this source and the only place of call is safe, because routine Test() always calls with n at least 1.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
have a code:
cppcheck 2.14 says:
tmp.c:10:12: warning: Uninitialized variable: buf [uninitvar]
return buf[n / 2];
^
tmp.c:6:18: note: Assuming condition is false
for(i = 0; i < n; i++)
^
tmp.c:10:12: note: Uninitialized variable: buf
return buf[n / 2];
^
However n is always at least 1, so the used part of the buf is always set.
I know, it requires global analysis :-)
So
GetValue()
must not be called withn == 0
, which is dangerous at best.We also warn for
Yes, it is dangerous to call GetValue(0), however this case will never happen. The function is static, so not callable from outside of this source and the only place of call is safe, because routine Test() always calls with n at least 1.