Skip to content
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

[C][Client][Clang Static Analyzer] Fix uninitialized argument value (Part-2) #7332

Merged
merged 1 commit into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ end:

// header parameters
char *keyHeader_{{{paramName}}} = NULL;
{{#isPrimitiveType}}{{#isNumber}}{{{dataType}}}{{/isNumber}}{{#isLong}}{{{dataType}}}{{/isLong}}{{#isInteger}}{{{dataType}}}{{/isInteger}}{{#isDouble}}{{{dataType}}}{{/isDouble}}{{#isFloat}}{{{dataType}}}{{/isFloat}}{{#isBoolean}}{{dataType}}{{/isBoolean}}{{#isEnum}}{{#isString}}{{projectName}}_{{operationId}}_{{baseName}}_e{{/isString}}{{/isEnum}}{{^isEnum}}{{#isString}}{{{dataType}}} *{{/isString}}{{/isEnum}}{{#isByteArray}}{{{dataType}}}{{/isByteArray}}{{#isDate}}{{{dataType}}}{{/isDate}}{{#isDateTime}}{{{dataType}}}{{/isDateTime}}{{#isFile}}{{{dataType}}}{{/isFile}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}}{{/isEmail}}{{/isPrimitiveType}} valueHeader_{{{paramName}}};
{{#isPrimitiveType}}{{#isNumber}}{{{dataType}}}{{/isNumber}}{{#isLong}}{{{dataType}}}{{/isLong}}{{#isInteger}}{{{dataType}}}{{/isInteger}}{{#isDouble}}{{{dataType}}}{{/isDouble}}{{#isFloat}}{{{dataType}}}{{/isFloat}}{{#isBoolean}}{{dataType}}{{/isBoolean}}{{#isEnum}}{{#isString}}{{projectName}}_{{operationId}}_{{baseName}}_e{{/isString}}{{/isEnum}}{{^isEnum}}{{#isString}}{{{dataType}}} *{{/isString}}{{/isEnum}}{{#isByteArray}}{{{dataType}}}{{/isByteArray}}{{#isDate}}{{{dataType}}}{{/isDate}}{{#isDateTime}}{{{dataType}}}{{/isDateTime}}{{#isFile}}{{{dataType}}}{{/isFile}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}}{{/isEmail}}{{/isPrimitiveType}} valueHeader_{{{paramName}}} = 0;
keyValuePair_t *keyPairHeader_{{paramName}} = 0;
if ({{paramName}}) {
keyHeader_{{{paramName}}} = strdup("{{{baseName}}}");
Expand Down Expand Up @@ -243,12 +243,12 @@ end:
// form parameters
{{#isFile}}
char *keyForm_{{paramName}} = NULL;
{{{dataType}}} valueForm_{{paramName}};
{{{dataType}}} valueForm_{{paramName}} = 0;
keyValuePair_t *keyPairForm_{{paramName}} = 0;
{{/isFile}}
{{^isFile}}
char *keyForm_{{paramName}} = NULL;
{{#isPrimitiveType}}{{#isNumber}}{{{dataType}}}{{/isNumber}}{{#isLong}}{{{dataType}}}{{/isLong}}{{#isInteger}}{{{dataType}}}{{/isInteger}}{{#isDouble}}{{{dataType}}}{{/isDouble}}{{#isFloat}}{{{dataType}}}{{/isFloat}}{{#isBoolean}}{{dataType}}{{/isBoolean}}{{#isEnum}}{{#isString}}{{projectName}}_{{operationId}}_{{baseName}}_e{{/isString}}{{/isEnum}}{{^isEnum}}{{#isString}}{{{dataType}}} *{{/isString}}{{/isEnum}}{{#isByteArray}}{{{dataType}}}{{/isByteArray}}{{#isDate}}{{{dataType}}}{{/isDate}}{{#isDateTime}}{{{dataType}}}{{/isDateTime}}{{#isFile}}{{{dataType}}}{{/isFile}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}}{{/isEmail}}{{/isPrimitiveType}} valueForm_{{paramName}};
{{#isPrimitiveType}}{{#isNumber}}{{{dataType}}}{{/isNumber}}{{#isLong}}{{{dataType}}}{{/isLong}}{{#isInteger}}{{{dataType}}}{{/isInteger}}{{#isDouble}}{{{dataType}}}{{/isDouble}}{{#isFloat}}{{{dataType}}}{{/isFloat}}{{#isBoolean}}{{dataType}}{{/isBoolean}}{{#isEnum}}{{#isString}}{{projectName}}_{{operationId}}_{{baseName}}_e{{/isString}}{{/isEnum}}{{^isEnum}}{{#isString}}{{{dataType}}} *{{/isString}}{{/isEnum}}{{#isByteArray}}{{{dataType}}}{{/isByteArray}}{{#isDate}}{{{dataType}}}{{/isDate}}{{#isDateTime}}{{{dataType}}}{{/isDateTime}}{{#isFile}}{{{dataType}}}{{/isFile}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}}{{/isEmail}}{{/isPrimitiveType}} valueForm_{{paramName}} = 0;
keyValuePair_t *keyPairForm_{{paramName}} = 0;
{{/isFile}}
if ({{paramName}} != NULL)
Expand Down Expand Up @@ -403,7 +403,10 @@ end:
free(keyHeader_{{{paramName}}});
keyHeader_{{{paramName}}} = NULL;
}
free(valueHeader_{{{paramName}}});
if (valueHeader_{{{paramName}}}) {
free(valueHeader_{{{paramName}}});
valueHeader_{{{paramName}}} = NULL;
}
{{/isString}}
{{^isString}}
if (keyHeader_{{{paramName}}}) {
Expand Down Expand Up @@ -483,7 +486,10 @@ end:
free(keyForm_{{{paramName}}});
keyForm_{{{paramName}}} = NULL;
}
free(valueForm_{{{paramName}}});
if (valueForm_{{{paramName}}}) {
free(valueForm_{{{paramName}}});
valueForm_{{{paramName}}} = NULL;
}
free(keyPairForm_{{paramName}});
{{/isString}}
{{^isString}}
Expand Down Expand Up @@ -523,7 +529,10 @@ end:
free(keyHeader_{{{paramName}}});
keyHeader_{{{paramName}}} = NULL;
}
free(valueHeader_{{{paramName}}});
if (valueHeader_{{{paramName}}}) {
free(valueHeader_{{{paramName}}});
valueHeader_{{{paramName}}} = NULL;
}
{{/isString}}
{{^isString}}
if (keyHeader_{{{paramName}}}) {
Expand Down Expand Up @@ -600,7 +609,10 @@ end:
free(keyForm_{{{paramName}}});
keyForm_{{{paramName}}} = NULL;
}
free(valueForm_{{{paramName}}});
if (valueForm_{{{paramName}}}) {
free(valueForm_{{{paramName}}});
valueForm_{{{paramName}}} = NULL;
}
keyValuePair_free(keyPairForm_{{{paramName}}});
{{/isString}}
{{^isString}}
Expand Down
30 changes: 21 additions & 9 deletions samples/client/petstore/c/api/PetAPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ PetAPI_deletePet(apiClient_t *apiClient, long petId , char * api_key )

// header parameters
char *keyHeader_api_key = NULL;
char * valueHeader_api_key;
char * valueHeader_api_key = 0;
keyValuePair_t *keyPairHeader_api_key = 0;
if (api_key) {
keyHeader_api_key = strdup("api_key");
Expand Down Expand Up @@ -195,7 +195,10 @@ PetAPI_deletePet(apiClient_t *apiClient, long petId , char * api_key )
free(keyHeader_api_key);
keyHeader_api_key = NULL;
}
free(valueHeader_api_key);
if (valueHeader_api_key) {
free(valueHeader_api_key);
valueHeader_api_key = NULL;
}
free(keyPairHeader_api_key);

}
Expand Down Expand Up @@ -554,7 +557,7 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId , char * name , char

// form parameters
char *keyForm_name = NULL;
char * valueForm_name;
char * valueForm_name = 0;
keyValuePair_t *keyPairForm_name = 0;
if (name != NULL)
{
Expand All @@ -566,7 +569,7 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId , char * name , char

// form parameters
char *keyForm_status = NULL;
char * valueForm_status;
char * valueForm_status = 0;
keyValuePair_t *keyPairForm_status = 0;
if (status != NULL)
{
Expand Down Expand Up @@ -607,13 +610,19 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId , char * name , char
free(keyForm_name);
keyForm_name = NULL;
}
free(valueForm_name);
if (valueForm_name) {
free(valueForm_name);
valueForm_name = NULL;
}
keyValuePair_free(keyPairForm_name);
if (keyForm_status) {
free(keyForm_status);
keyForm_status = NULL;
}
free(valueForm_status);
if (valueForm_status) {
free(valueForm_status);
valueForm_status = NULL;
}
keyValuePair_free(keyPairForm_status);

}
Expand Down Expand Up @@ -654,7 +663,7 @@ PetAPI_uploadFile(apiClient_t *apiClient, long petId , char * additionalMetadata

// form parameters
char *keyForm_additionalMetadata = NULL;
char * valueForm_additionalMetadata;
char * valueForm_additionalMetadata = 0;
keyValuePair_t *keyPairForm_additionalMetadata = 0;
if (additionalMetadata != NULL)
{
Expand All @@ -666,7 +675,7 @@ PetAPI_uploadFile(apiClient_t *apiClient, long petId , char * additionalMetadata

// form parameters
char *keyForm_file = NULL;
binary_t* valueForm_file;
binary_t* valueForm_file = 0;
keyValuePair_t *keyPairForm_file = 0;
if (file != NULL)
{
Expand Down Expand Up @@ -715,7 +724,10 @@ PetAPI_uploadFile(apiClient_t *apiClient, long petId , char * additionalMetadata
free(keyForm_additionalMetadata);
keyForm_additionalMetadata = NULL;
}
free(valueForm_additionalMetadata);
if (valueForm_additionalMetadata) {
free(valueForm_additionalMetadata);
valueForm_additionalMetadata = NULL;
}
free(keyPairForm_additionalMetadata);
if (keyForm_file) {
free(keyForm_file);
Expand Down