[libbdplus-devel] check for NULL
anonymous
git at videolan.org
Fri Mar 3 14:33:01 CET 2017
libbdplus | branch: master | anonymous <anonymous at anonymous.org> | Fri Mar 3 14:58:42 2017 +0200| [b90f667168a6e9f3a6b74a2344cbd7984d3f9bde] | committer: anonymous
check for NULL
> http://git.videolan.org/gitweb.cgi/libbdplus.git/?a=commit;h=b90f667168a6e9f3a6b74a2344cbd7984d3f9bde
---
src/file/dirs_win32.c | 11 +++++++----
src/file/dirs_xdg.c | 4 +++-
src/file/file_default.c | 6 ++++++
src/util/strutl.c | 11 ++++++++++-
4 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/src/file/dirs_win32.c b/src/file/dirs_win32.c
index 9389711..009f046 100644
--- a/src/file/dirs_win32.c
+++ b/src/file/dirs_win32.c
@@ -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");
diff --git a/src/file/dirs_xdg.c b/src/file/dirs_xdg.c
index b9e5c2a..0ab3fdf 100644
--- a/src/file/dirs_xdg.c
+++ b/src/file/dirs_xdg.c
@@ -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;
diff --git a/src/file/file_default.c b/src/file/file_default.c
index 93f836e..3dbbde3 100644
--- a/src/file/file_default.c
+++ b/src/file/file_default.c
@@ -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;
diff --git a/src/util/strutl.c b/src/util/strutl.c
index b1a4a21..910fb9c 100644
--- a/src/util/strutl.c
+++ b/src/util/strutl.c
@@ -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, ...)
More information about the libbdplus-devel
mailing list