Skip to content

Commit 4bee238

Browse files
committed
GetModuleFileName() doesn't reset last error on success
1 parent 4af3ca4 commit 4bee238

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

modules/videoio/src/cap_ffmpeg.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,10 @@ class icvInitFFMPEG
124124
if (m)
125125
{
126126
wchar_t path[MAX_PATH];
127-
size_t sz = GetModuleFileNameW(m, path, sizeof(path));
128-
if (sz > 0 && ERROR_SUCCESS == GetLastError())
127+
const size_t path_size = sizeof(path)/sizeof(*path);
128+
size_t sz = GetModuleFileNameW(m, path, path_size);
129+
/* Don't handle paths longer than MAX_PATH until that becomes a real issue */
130+
if (sz > 0 && sz < path_size)
129131
{
130132
wchar_t* s = wcsrchr(path, L'\\');
131133
if (s)

0 commit comments

Comments
 (0)