fix: invalid jumps on uninitialized variable

This commit is contained in:
jonathan santis
2025-05-15 13:01:46 +02:00
parent 9225740cd4
commit c352788ef5
2 changed files with 7 additions and 4 deletions

View File

@@ -189,6 +189,8 @@ int parseConfig(char *buffer,struct configEntry **entry,int configSizeCount,int
case ST_FOUND_SECTION: case ST_FOUND_SECTION:
keyName = malloc(MAX_LEN_SECTIONNAME); keyName = malloc(MAX_LEN_SECTIONNAME);
keyValue = malloc(MAX_LEN_SECTIONNAME); keyValue = malloc(MAX_LEN_SECTIONNAME);
memset(keyName,0,MAX_LEN_SECTIONNAME);
memset(keyValue,0,MAX_LEN_SECTIONNAME);
if((ret=getNameValuePair(token,'=',0, if((ret=getNameValuePair(token,'=',0,
&keyName,&keyValue, &keyName,&keyValue,
MAX_LEN_SECTIONNAME,MAX_LEN_SECTIONNAME MAX_LEN_SECTIONNAME,MAX_LEN_SECTIONNAME
@@ -225,8 +227,6 @@ int parseConfig(char *buffer,struct configEntry **entry,int configSizeCount,int
} }
} }
free(keyName);
free(keyValue);
free(sectionName); free(sectionName);
return NO_ERROR; return NO_ERROR;
} }

7
test.c
View File

@@ -24,6 +24,7 @@ int main(void)
{ {
free(sectionName); free(sectionName);
printf("an error occured:%d\n",ret); printf("an error occured:%d\n",ret);
return 1;
} }
char testpair[] = "asifdsfo=s1254124"; char testpair[] = "asifdsfo=s1254124";
@@ -56,6 +57,7 @@ int main(void)
return 1; return 1;
} }
content = malloc(neededSize); content = malloc(neededSize);
memset(content,0,neededSize);
if((ret=getFile("config.cfg",&content,neededSize,&neededSize))==NO_ERROR) if((ret=getFile("config.cfg",&content,neededSize,&neededSize))==NO_ERROR)
{ {
printf("Sucessfull read file into buffer:%s\n---\n",content); printf("Sucessfull read file into buffer:%s\n---\n",content);
@@ -83,7 +85,8 @@ int main(void)
free(keyValue); free(keyValue);
free(keyName); free(keyName);
free(name); free(name);
free(entry->keyName);
free(sectionName);
return 0;
} }