Linux: Fix path buffer length warning

Fixes #1025.
This commit is contained in:
Camilla Löwy 2017-06-08 19:23:06 +02:00
parent 4dee58d480
commit 5bcf9c76fd
2 changed files with 12 additions and 2 deletions

View File

@ -182,6 +182,7 @@ information on what to include when reporting a bug.
- [X11] Bugfix: Gamma ramp setting via RandR did not validate ramp size - [X11] Bugfix: Gamma ramp setting via RandR did not validate ramp size
- [X11] Bugfix: Key name string encoding depended on current locale (#981,#983) - [X11] Bugfix: Key name string encoding depended on current locale (#981,#983)
- [Linux] Bugfix: Event processing did not detect joystick disconnection (#932) - [Linux] Bugfix: Event processing did not detect joystick disconnection (#932)
- [Linux] Bugfix: The joystick device path could be truncated (#1025)
- [Cocoa] Added support for Vulkan window surface creation via - [Cocoa] Added support for Vulkan window surface creation via
[MoltenVK](https://moltengl.com/moltenvk/) (#870) [MoltenVK](https://moltengl.com/moltenvk/) (#870)
- [Cocoa] Added support for loading a `MainMenu.nib` when available - [Cocoa] Added support for loading a `MainMenu.nib` when available

View File

@ -160,15 +160,24 @@ GLFWbool _glfwInitJoysticksLinux(void)
while ((entry = readdir(dir))) while ((entry = readdir(dir)))
{ {
char path[20];
regmatch_t match; regmatch_t match;
char* path = NULL;
if (regexec(&_glfw.linjs.regex, entry->d_name, 1, &match, 0) != 0) if (regexec(&_glfw.linjs.regex, entry->d_name, 1, &match, 0) != 0)
continue; continue;
snprintf(path, sizeof(path), "%s/%s", dirname, entry->d_name); if (asprintf(&path, "%s/%s", dirname, entry->d_name) < 0)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Linux: Failed to construct device path: %s",
strerror(errno));
continue;
}
if (openJoystickDevice(path)) if (openJoystickDevice(path))
count++; count++;
free(path);
} }
closedir(dir); closedir(dir);