mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
dtcalc/ds_xlib.c: coverity CID 175093; wrong sizeof/bad free
This commit is contained in:
parent
75a892d93f
commit
ce471d7068
2 changed files with 26 additions and 11 deletions
|
@ -35,6 +35,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -255,14 +257,23 @@ ds_save_resources(XrmDatabase rDB, char *filename)
|
||||||
{
|
{
|
||||||
char *home;
|
char *home;
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
|
bool needsFree = false;
|
||||||
|
|
||||||
if (filename == NULL)
|
if (filename == NULL)
|
||||||
{
|
{
|
||||||
if ((filename = getenv("DTCALCDEF")) == NULL)
|
if ((filename = getenv("DTCALCDEF")) == NULL)
|
||||||
{
|
{
|
||||||
|
size_t fileLen = strlen(home) + 18;
|
||||||
home = getenv("HOME");
|
home = getenv("HOME");
|
||||||
filename = (char*) calloc(1, strlen(home) + 18) ;
|
if ( (filename = calloc(1, fileLen)) != NULL )
|
||||||
snprintf(filename, sizeof(filename), "%s/.dtcalcdef", home) ;
|
{
|
||||||
|
needsFree = true;
|
||||||
|
snprintf(filename, fileLen, "%s/.dtcalcdef", home);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,14 +281,18 @@ ds_save_resources(XrmDatabase rDB, char *filename)
|
||||||
|
|
||||||
if (stat(filename, &statbuf) != -1 && access(filename, W_OK) != 0)
|
if (stat(filename, &statbuf) != -1 && access(filename, W_OK) != 0)
|
||||||
{
|
{
|
||||||
|
if (needsFree)
|
||||||
free(filename);
|
free(filename);
|
||||||
|
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If file does not exist this call will create it. */
|
/* If file does not exist this call will create it. */
|
||||||
|
|
||||||
XrmPutFileDatabase(rDB, filename);
|
XrmPutFileDatabase(rDB, filename);
|
||||||
|
if (needsFree)
|
||||||
free(filename);
|
free(filename);
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -177,4 +177,4 @@ XVars X ;
|
||||||
#define HOME_RESTORE 1
|
#define HOME_RESTORE 1
|
||||||
#define CURRENT_RESTORE 2
|
#define CURRENT_RESTORE 2
|
||||||
|
|
||||||
#define MAX_PATH 1024
|
#define MAX_PATH PATH_MAX
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue