fix: invalid jumps on uninitialized variable
This commit is contained in:
10
config.c
10
config.c
@@ -69,12 +69,8 @@ int checkSection(char *str,char delimiterLeft,char delimiterRight,char **section
|
|||||||
break;
|
break;
|
||||||
case ST_FOUND_RIGHT_DELIMITER:
|
case ST_FOUND_RIGHT_DELIMITER:
|
||||||
int ret=0;
|
int ret=0;
|
||||||
sectionName2 = malloc(MAX_LEN_SECTIONNAME);
|
if((ret=getStrAtPos(str,leftDelimiterPos,rightDelimiterPos,sectionName,MAX_LEN_SECTIONNAME)) == NO_ERROR)
|
||||||
memset(sectionName2,0,MAX_LEN_SECTIONNAME);
|
|
||||||
if((ret=getStrAtPos(str,leftDelimiterPos,rightDelimiterPos,§ionName2,MAX_LEN_SECTIONNAME)) == NO_ERROR)
|
|
||||||
{
|
{
|
||||||
*sectionName = strdup(sectionName2);
|
|
||||||
free(sectionName2);
|
|
||||||
state = ST_FINISH;
|
state = ST_FINISH;
|
||||||
}else{
|
}else{
|
||||||
return ret;
|
return ret;
|
||||||
@@ -169,7 +165,7 @@ int parseConfig(char *buffer,struct configEntry **entry,int configSizeCount,int
|
|||||||
char *keyName=NULL;
|
char *keyName=NULL;
|
||||||
char *keyValue=NULL;
|
char *keyValue=NULL;
|
||||||
|
|
||||||
sectionName = malloc(MAX_LEN_SECTIONNAME);
|
|
||||||
|
|
||||||
//read buffer line by line
|
//read buffer line by line
|
||||||
char *token;
|
char *token;
|
||||||
@@ -179,6 +175,7 @@ int parseConfig(char *buffer,struct configEntry **entry,int configSizeCount,int
|
|||||||
switch(state)
|
switch(state)
|
||||||
{
|
{
|
||||||
case ST_INIT:
|
case ST_INIT:
|
||||||
|
sectionName = malloc(MAX_LEN_SECTIONNAME);
|
||||||
printf("token(line): %s\n",token);
|
printf("token(line): %s\n",token);
|
||||||
|
|
||||||
if((ret=checkSection(token,'[',']',§ionName))==FOUND_SECTION)
|
if((ret=checkSection(token,'[',']',§ionName))==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].sectionName = strdup(sectionName);
|
||||||
ptr_entry[i].keyValue= strdup(keyValue);
|
ptr_entry[i].keyValue= strdup(keyValue);
|
||||||
ptr_entry[i].keyName = strdup(keyName);
|
ptr_entry[i].keyName = strdup(keyName);
|
||||||
|
free(sectionName);
|
||||||
free(keyName);
|
free(keyName);
|
||||||
free(keyValue);
|
free(keyValue);
|
||||||
if(i<configSizeCount-1)
|
if(i<configSizeCount-1)
|
||||||
|
|||||||
Reference in New Issue
Block a user