[libbluray-devel] Check MultiByteToWideChar() return value

hpi1 git at videolan.org
Sun Aug 7 13:33:26 CEST 2016


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Sat Aug  6 18:58:22 2016 +0300| [e057d211a046e98d503d83e2f760b42b87f40bd4] | committer: hpi1

Check MultiByteToWideChar() return value

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=e057d211a046e98d503d83e2f760b42b87f40bd4
---

 src/file/dir_win32.c  |  4 +++-
 src/file/file_win32.c | 13 ++++++++++---
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/file/dir_win32.c b/src/file/dir_win32.c
index 2690658..9e3190a 100644
--- a/src/file/dir_win32.c
+++ b/src/file/dir_win32.c
@@ -62,7 +62,9 @@ static int _dir_read_win32(BD_DIR_H *dir, BD_DIRENT *entry)
     if (!priv->info.name[0]) {
         return 1;
     }
-    WideCharToMultiByte(CP_UTF8, 0, priv->info.name, -1, entry->d_name, sizeof(entry->d_name), NULL, NULL);
+    if (!WideCharToMultiByte(CP_UTF8, 0, priv->info.name, -1, entry->d_name, sizeof(entry->d_name), NULL, NULL)) {
+        return -1;
+    }
 
     priv->info.name[0] = 0;
     _wfindnext(priv->handle, &priv->info);
diff --git a/src/file/file_win32.c b/src/file/file_win32.c
index d9845fb..11aaf82 100644
--- a/src/file/file_win32.c
+++ b/src/file/file_win32.c
@@ -152,7 +152,10 @@ int file_unlink(const char *file)
 {
     wchar_t wfile[MAX_PATH];
 
-    MultiByteToWideChar(CP_UTF8, 0, file, -1, wfile, MAX_PATH);
+    if (!MultiByteToWideChar(CP_UTF8, 0, file, -1, wfile, MAX_PATH)) {
+        return -1;
+    }
+
     return _wremove(wfile);
 }
 
@@ -160,7 +163,9 @@ int file_path_exists(const char *path)
 {
     wchar_t wpath[MAX_PATH];
 
-    MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, MAX_PATH);
+    if (!MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, MAX_PATH)) {
+        return -1;
+    }
 
     DWORD dwAttrib = GetFileAttributesW(wpath);
     if (dwAttrib != INVALID_FILE_ATTRIBUTES) {
@@ -173,7 +178,9 @@ int file_mkdir(const char *dir)
 {
     wchar_t wdir[MAX_PATH];
 
-    MultiByteToWideChar(CP_UTF8, 0, dir, -1, wdir, MAX_PATH);
+    if (!MultiByteToWideChar(CP_UTF8, 0, dir, -1, wdir, MAX_PATH)) {
+        return -1;
+    }
     if (!CreateDirectoryW(wdir, NULL))
         return -1;
     return 0;



More information about the libbluray-devel mailing list