Commit b90f6671 authored by anonymous's avatar anonymous
Browse files

check for NULL

parent 9a59dc5a
......@@ -28,10 +28,9 @@
#include <stdio.h>
#include <string.h>
#include <shlobj.h>
#include <windows.h>
#include <shlobj.h>
#include <limits.h>
#include <direct.h>
int win32_mkdir(const char *dir)
......@@ -56,7 +55,9 @@ char *file_get_data_home(void)
NULL, SHGFP_TYPE_CURRENT, wdir)) {
int len = WideCharToMultiByte (CP_UTF8, 0, wdir, -1, NULL, 0, NULL, NULL);
char *appdir = malloc(len);
WideCharToMultiByte (CP_UTF8, 0, wdir, -1, appdir, len, NULL, NULL);
if (appdir) {
WideCharToMultiByte (CP_UTF8, 0, wdir, -1, appdir, len, NULL, NULL);
}
return appdir;
}
......@@ -85,7 +86,9 @@ const char *file_get_config_system(const char *dir)
NULL, SHGFP_TYPE_CURRENT, wdir)) {
int len = WideCharToMultiByte (CP_UTF8, 0, wdir, -1, NULL, 0, NULL, NULL);
appdir = malloc(len);
WideCharToMultiByte (CP_UTF8, 0, wdir, -1, appdir, len, NULL, NULL);
if (appdir) {
WideCharToMultiByte (CP_UTF8, 0, wdir, -1, appdir, len, NULL, NULL);
}
return appdir;
} else {
BD_DEBUG(DBG_FILE, "Can't find common configuration directory !\n");
......
......@@ -26,7 +26,6 @@
#include "util/strutl.h"
#include "util/logging.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -99,6 +98,9 @@ const char *file_get_config_system(const char *dir)
if (xdg_sys && *xdg_sys) {
dirs = calloc(1, strlen(xdg_sys) + 2);
if (!dirs) {
return NULL;
}
strcpy(dirs, xdg_sys);
char *pt = dirs;
......
......@@ -77,6 +77,12 @@ BDPLUS_FILE_H *file_open_default(void *handle, const char* file_name)
}
file = calloc(1, sizeof(BDPLUS_FILE_H));
if (!file) {
BD_DEBUG(DBG_CRIT, "out of memory\n");
fclose(fp);
return NULL;
}
file->internal = fp;
file->close = _file_close;
file->seek = _file_seek;
......
......@@ -33,7 +33,16 @@
char *str_dup(const char *str)
{
return str ? strcpy (malloc(strlen(str) + 1), str) : NULL;
char *dup = NULL;
if (str) {
size_t size = strlen(str) + 1;
dup = malloc(size);
if (dup) {
memcpy(dup, str, size);
}
}
return dup;
}
char *str_printf(const char *fmt, ...)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment