-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Address spurious Microsoft compiler warnings #49
Conversation
@@ -1248,7 +1248,7 @@ static JSONStatus_t search( char * buf, | |||
size_t * outValueLength ) | |||
{ | |||
JSONStatus_t ret = JSONPartial; | |||
size_t i = 0, key, keyLength, value, valueLength; | |||
size_t i = 0, key, keyLength, value = 0, valueLength = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what abt key
and keyLength
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no warnings for key and keyLength. I think it is better to enlist the compiler to tell me when I use an uninitialized variable, than to initialize everything and rob myself of that check. The only problem is when the compiler gets it wrong, as the Microsoft compiler does here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think that it's good practice to just initialize everything anyways as part of our style?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, not everything. I think the practice can do more harm than good in some cases.
Different compilers seem to have different capacities to recognize use of an uninitialized variable. The GNU toolchain gives no warnings, but the Microsoft compiler does. Upon inspection, the variables are only ever used after being set, but it is simpler to provide throwaway defaults than to mute the warning.