mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
dtcreate: Fix some memory management issues
ProcessExecString thought it was returning an array of size 3; however in C arrays are second-class and there is no direct way to return an array like this; GCC warning triggered because it was actually just returning a pointer to local storage. Fixed using malloc. Also fix some obviously wrong usages of sizeof, although they were relatively harmless. A little other warning quieting using 0 instead of NULL.
This commit is contained in:
parent
c8a5b9671f
commit
7d2fee2769
1 changed files with 20 additions and 13 deletions
|
@ -140,8 +140,8 @@ char linebuf[1024],**wordPairs,**execstr;
|
||||||
rewind(fp);
|
rewind(fp);
|
||||||
/* Initialize the ActionData structure passed */
|
/* Initialize the ActionData structure passed */
|
||||||
if(ActionDataptr)
|
if(ActionDataptr)
|
||||||
memset((ActionData *)ActionDataptr,
|
memset(ActionDataptr,
|
||||||
NULL,sizeof(ActionData));
|
0,sizeof(ActionData));
|
||||||
else {
|
else {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("ActionDataptr is NULL\n");
|
printf("ActionDataptr is NULL\n");
|
||||||
|
@ -278,6 +278,7 @@ char linebuf[1024],**wordPairs,**execstr;
|
||||||
{
|
{
|
||||||
ActionDataptr->pszCmd = execstr[0];
|
ActionDataptr->pszCmd = execstr[0];
|
||||||
ActionDataptr->pszPrompt = execstr[1];
|
ActionDataptr->pszPrompt = execstr[1];
|
||||||
|
free(execstr);
|
||||||
}
|
}
|
||||||
/* Got the ActionData,so, go get the FiletypeData */
|
/* Got the ActionData,so, go get the FiletypeData */
|
||||||
ActionDataptr->papFiletypes =
|
ActionDataptr->papFiletypes =
|
||||||
|
@ -432,8 +433,10 @@ FiletypeData **ppFiletypeData,**ppnewFiletypeData;
|
||||||
/* Everything looks right so process the exec_string */
|
/* Everything looks right so process the exec_string */
|
||||||
if( !(execstr = ProcessExecString((char *)ppFiletypeData[nfiletypes]->pszPrintCmd)) )
|
if( !(execstr = ProcessExecString((char *)ppFiletypeData[nfiletypes]->pszPrintCmd)) )
|
||||||
ppFiletypeData[nfiletypes]->pszPrintCmd=NULL;
|
ppFiletypeData[nfiletypes]->pszPrintCmd=NULL;
|
||||||
else
|
else {
|
||||||
ppFiletypeData[nfiletypes]->pszPrintCmd=execstr[0];
|
ppFiletypeData[nfiletypes]->pszPrintCmd=execstr[0];
|
||||||
|
free(execstr);
|
||||||
|
}
|
||||||
nfiletypes++;
|
nfiletypes++;
|
||||||
/* Allocate a new filetypedata record */
|
/* Allocate a new filetypedata record */
|
||||||
if( (ppFiletypeData[nfiletypes] =
|
if( (ppFiletypeData[nfiletypes] =
|
||||||
|
@ -693,24 +696,26 @@ GetKeywordValuePairs(char *s, int *id, int table)
|
||||||
++s;
|
++s;
|
||||||
if (!args[0])
|
if (!args[0])
|
||||||
{
|
{
|
||||||
args[0] = (char *)malloc (s - wordStart + 1);
|
int szArgs0 = s - wordStart + 1;
|
||||||
|
args[0] = (char *)malloc (szArgs0);
|
||||||
if (!args[0])
|
if (!args[0])
|
||||||
return NULL;
|
return NULL;
|
||||||
memset(args[0],0,sizeof(args[0]));
|
memset(args[0],0,szArgs0);
|
||||||
}
|
}
|
||||||
strncpy (args[0], wordStart, s - wordStart);
|
strncpy (args[0], wordStart, s - wordStart);
|
||||||
args[0][s-wordStart] = '\0';
|
args[0][s-wordStart] = '\0';
|
||||||
if (!args[1])
|
if (!args[1])
|
||||||
{
|
{
|
||||||
|
int szArgs1 = strlen(s) + 1;
|
||||||
if(s)
|
if(s)
|
||||||
args[1] = (char *)malloc (strlen(s)+1);
|
args[1] = (char *)malloc (szArgs1);
|
||||||
if (!args[1])
|
if (!args[1])
|
||||||
{
|
{
|
||||||
if(args[0])
|
if(args[0])
|
||||||
free(args[0]);
|
free(args[0]);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memset(args[1],0,sizeof(args[1]));
|
memset(args[1],0,szArgs1);
|
||||||
}
|
}
|
||||||
/* Skip all leading spaces */
|
/* Skip all leading spaces */
|
||||||
while (*s && isspace (*s))
|
while (*s && isspace (*s))
|
||||||
|
@ -806,8 +811,8 @@ GetKeywordValuePairs(char *s, int *id, int table)
|
||||||
** **
|
** **
|
||||||
** Limitation : Supports only ONE prompt. **
|
** Limitation : Supports only ONE prompt. **
|
||||||
** **
|
** **
|
||||||
** Output : returns 0 (No error). **
|
** Output : Pointer to 3-element result array from malloc, **
|
||||||
** returns >0 (Error). **
|
** or NULL on error **
|
||||||
** **
|
** **
|
||||||
** Assumptions: a) Arg fields start with a '%' character. **
|
** Assumptions: a) Arg fields start with a '%' character. **
|
||||||
** b) Prompt string start and end with '"' chara- **
|
** b) Prompt string start and end with '"' chara- **
|
||||||
|
@ -822,13 +827,15 @@ char **
|
||||||
ProcessExecString(char *cmd)
|
ProcessExecString(char *cmd)
|
||||||
{
|
{
|
||||||
|
|
||||||
char *s1, *s2,*s3,*s4,*argbuf,*exec_args[3];
|
char *s1, *s2,*s3,*s4,*argbuf,**exec_args;
|
||||||
int done=FALSE, argfound=FALSE,promptfound=FALSE;
|
int done=FALSE, argfound=FALSE,promptfound=FALSE;
|
||||||
|
|
||||||
if (!cmd) {
|
if (!cmd) {
|
||||||
return((char **)NULL);
|
return((char **)NULL);
|
||||||
}
|
}
|
||||||
s1=s2=s3=s4=argbuf=NULL;
|
s1=s2=s3=s4=argbuf=NULL;
|
||||||
|
exec_args = calloc(3, sizeof(char*));
|
||||||
|
if (!exec_args) return NULL;
|
||||||
/* Allocate buffer for the cmd string */
|
/* Allocate buffer for the cmd string */
|
||||||
exec_args[0] = (char *)calloc(1,strlen(cmd)+1);
|
exec_args[0] = (char *)calloc(1,strlen(cmd)+1);
|
||||||
exec_args[1] = exec_args[2] = NULL;
|
exec_args[1] = exec_args[2] = NULL;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue