commit 711f136f3c77e21c0274c2a569f1854c28cb7385
parent b14053bea488126a2cb64f176e480bbc456b9d23
Author: Christian Grothoff <christian@grothoff.org>
Date: Sat, 12 Jun 2010 21:04:54 +0000
cleanup
Diffstat:
3 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/src/main/extract.c b/src/main/extract.c
@@ -553,6 +553,13 @@ main (int argc, char *argv[])
ignore_sigpipe ();
#endif
print = malloc (sizeof (int) * EXTRACTOR_metatype_get_max ());
+ if (print == NULL)
+ {
+ fprintf (stderr,
+ "malloc failed: %s\n",
+ strerror (errno));
+ return 1;
+ }
for (i = 0; i < EXTRACTOR_metatype_get_max (); i++)
print[i] = YES; /* default: print everything */
diff --git a/src/main/extractor.c b/src/main/extractor.c
@@ -177,11 +177,11 @@ get_path_from_proc_exe() {
char * lnk;
char * ret;
char * lestr;
- size_t size;
+ ssize_t size;
FILE * f;
snprintf(fn,
- 64,
+ sizeof (fn),
"/proc/%u/maps",
getpid());
f = fopen(fn, "r");
@@ -200,14 +200,14 @@ get_path_from_proc_exe() {
fclose(f);
}
snprintf(fn,
- 64,
+ sizeof (fn),
"/proc/%u/exe",
getpid());
lnk = malloc(1029); /* 1024 + 5 for "lib/" catenation */
if (lnk == NULL)
return NULL;
size = readlink(fn, lnk, 1023);
- if ( (size == 0) || (size >= 1024) ) {
+ if ( (size <= 0) || (size >= 1024) ) {
free(lnk);
return NULL;
}
@@ -391,14 +391,18 @@ append_to_dir (const char *path,
const char *fname)
{
char *ret;
+ size_t slen;
+ slen = strlen (path);
+ if (slen == 0)
+ return NULL;
if (fname[0] == DIR_SEPARATOR)
fname++;
- ret = malloc (strlen (path) + strlen(fname) + 2);
+ ret = malloc (slen + strlen(fname) + 2);
if (ret == NULL)
return NULL;
#ifdef MINGW
- if (path[strlen(path)-1] == '\\')
+ if (path[slen-1] == '\\')
sprintf (ret,
"%s%s",
path,
@@ -409,7 +413,7 @@ append_to_dir (const char *path,
path,
fname);
#else
- if (path[strlen(path)-1] == '/')
+ if (path[slen-1] == '/')
sprintf (ret,
"%s%s",
path,
diff --git a/src/plugins/it_extractor.c b/src/plugins/it_extractor.c
@@ -75,9 +75,10 @@ EXTRACTOR_it_extract (const char *data,
return 1;
/* Version of Tracker */
- sprintf (itversion,
- "%d.%d",
- (head->version[0]& 0x01),head->version[1]);
+ snprintf (itversion,
+ sizeof (itversion),
+ "%d.%d",
+ (head->version[0]& 0x01),head->version[1]);
if (0 != proc (proc_cls,
"it",
EXTRACTOR_METATYPE_FORMAT_VERSION,