fix: null termnination on file buffer

This commit is contained in:
jonathan santis
2025-05-19 14:56:34 +02:00
parent ff1b01e4be
commit d3e0c75f6c
4 changed files with 104 additions and 12 deletions

View File

@@ -112,7 +112,35 @@ int getStrAtPos(char *str,int fromPos,int toPos,char **name,int sizeName)
//printf("*name:%s\n",ptr_name);
return NO_ERROR;
}
/*
*Here we get a "pair" of data, parsed from *str, witch consists of a keyname and a keyvalue.
*These are written to the pointers at char **name and char **value.
*These pair can be in the form of:
* ex1:
* NAME=VALUE
* ^ ^
* | Here we have no delimiter this means rightDelimiterPos must be NULL
* This is the left delimiter
* ex2:
* name(value)
* ^ ^
* | This is the rightDelimiterPos and must be ')'
* This is leftDelimiterPos which must be '('
*
* Input:
* char *str: the line in the form of a string where a key value pair is stored
* char leftDelimiterPos: the left delimiter for example '='
* char rightDelimiterPos: the right delimiter can be NULL in most cases, if NULL we assume that there is only one delimiter, which is in this case the leftDelimiterPos
* Output:
* char **name: The address where we store the name of the Key
* char **value: The address where we store the key value
* int sizeName: for size checking against memory allocated at **name
* int sizeValue: for size checking against memory allocated at **value
*
* Return:
* will return NO_ERROR (0) if successfull.
* If not it will return the error of the subroutine
*/
int getNameValuePair(char *str,char leftDelimiterPos,char rightDelimiterPos,char **name,char **value,int sizeName,int sizeValue)
{
@@ -132,7 +160,7 @@ int getNameValuePair(char *str,char leftDelimiterPos,char rightDelimiterPos,char
}
posDelimiter = (ptrDelimiter - str);
printf("LenUntilDelimiter: %d",posDelimiter);
if((ret=getStrAtPos(str,0,posDelimiter-1,&ptr_name,MAX_LEN_SECTIONNAME)) == NO_ERROR)
if((ret=getStrAtPos(str,0,posDelimiter-1,&ptr_name,sizeName)) == NO_ERROR)
{
printf("ptr_name:%s",ptr_name);
}else {
@@ -145,7 +173,7 @@ int getNameValuePair(char *str,char leftDelimiterPos,char rightDelimiterPos,char
posEnd = rightDelimiterPos;
}
if((ret=getStrAtPos(str,posDelimiter+1,posEnd,&ptr_value,MAX_LEN_SECTIONNAME)) == NO_ERROR)
if((ret=getStrAtPos(str,posDelimiter+1,posEnd,&ptr_value,sizeValue)) == NO_ERROR)
{
printf("ptr_name:%s\n",ptr_value);
}else {
@@ -155,6 +183,8 @@ int getNameValuePair(char *str,char leftDelimiterPos,char rightDelimiterPos,char
return NO_ERROR;
}
int parseConfig(char *buffer,struct configEntry **entry,int configSizeCount,int *returnedCount)
{
int state=ST_INIT;