fix: invalid jumps on uninitialized variable

This commit is contained in:
jonathan santis
2025-05-15 13:04:23 +02:00
parent c352788ef5
commit 00190b2354

View File

@@ -69,12 +69,8 @@ int checkSection(char *str,char delimiterLeft,char delimiterRight,char **section
break;
case ST_FOUND_RIGHT_DELIMITER:
int ret=0;
sectionName2 = malloc(MAX_LEN_SECTIONNAME);
memset(sectionName2,0,MAX_LEN_SECTIONNAME);
if((ret=getStrAtPos(str,leftDelimiterPos,rightDelimiterPos,&sectionName2,MAX_LEN_SECTIONNAME)) == NO_ERROR)
if((ret=getStrAtPos(str,leftDelimiterPos,rightDelimiterPos,sectionName,MAX_LEN_SECTIONNAME)) == NO_ERROR)
{
*sectionName = strdup(sectionName2);
free(sectionName2);
state = ST_FINISH;
}else{
return ret;
@@ -169,7 +165,7 @@ int parseConfig(char *buffer,struct configEntry **entry,int configSizeCount,int
char *keyName=NULL;
char *keyValue=NULL;
sectionName = malloc(MAX_LEN_SECTIONNAME);
//read buffer line by line
char *token;
@@ -179,6 +175,7 @@ int parseConfig(char *buffer,struct configEntry **entry,int configSizeCount,int
switch(state)
{
case ST_INIT:
sectionName = malloc(MAX_LEN_SECTIONNAME);
printf("token(line): %s\n",token);
if((ret=checkSection(token,'[',']',&sectionName))==FOUND_SECTION)
@@ -199,6 +196,7 @@ int parseConfig(char *buffer,struct configEntry **entry,int configSizeCount,int
ptr_entry[i].sectionName = strdup(sectionName);
ptr_entry[i].keyValue= strdup(keyValue);
ptr_entry[i].keyName = strdup(keyName);
free(sectionName);
free(keyName);
free(keyValue);
if(i<configSizeCount-1)