Skip to content

Commit 345c161

Browse files
committed
Fixed some accidental uses of external C runtime functions
1 parent 5d455ca commit 345c161

File tree

10 files changed

+47
-45
lines changed

10 files changed

+47
-45
lines changed

src/audio/nas/SDL_nasaudio.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ LoadNASLibrary(void)
113113
/* Copy error string so we can use it in a new SDL_SetError(). */
114114
const char *origerr = SDL_GetError();
115115
const size_t len = SDL_strlen(origerr) + 1;
116-
char *err = (char *) alloca(len);
116+
char *err = SDL_stack_alloc(char, len);
117117
SDL_strlcpy(err, origerr, len);
118+
SDL_SetError("NAS: SDL_LoadObject('%s') failed: %s", nas_library, err);
119+
SDL_stack_free(err);
118120
retval = -1;
119-
SDL_SetError("NAS: SDL_LoadObject('%s') failed: %s",
120-
nas_library, err);
121121
} else {
122122
retval = load_nas_syms();
123123
if (retval < 0) {

src/core/linux/SDL_evdev_kbd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ SDL_EVDEV_kbd_init(void)
386386
}
387387

388388
/* Allow inhibiting keyboard mute with env. variable for debugging etc. */
389-
if (getenv("SDL_INPUT_LINUX_KEEP_KBD") == NULL) {
389+
if (SDL_getenv("SDL_INPUT_LINUX_KEEP_KBD") == NULL) {
390390
/* Mute the keyboard so keystrokes only generate evdev events
391391
* and do not leak through to the console
392392
*/

src/filesystem/unix/SDL_sysfilesystem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ SDL_GetBasePath(void)
245245

246246
if (retval != NULL) {
247247
/* try to shrink buffer... */
248-
char *ptr = (char *) SDL_realloc(retval, strlen(retval) + 1);
248+
char *ptr = (char *) SDL_realloc(retval, SDL_strlen(retval) + 1);
249249
if (ptr != NULL)
250250
retval = ptr; /* oh well if it failed. */
251251
}

src/haptic/linux/SDL_syshaptic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ SDL_SYS_HapticInit(void)
166166
i = 0;
167167
for (j = 0; j < MAX_HAPTICS; ++j) {
168168

169-
snprintf(path, PATH_MAX, joydev_pattern, i++);
169+
SDL_snprintf(path, PATH_MAX, joydev_pattern, i++);
170170
MaybeAddDevice(path);
171171
}
172172

src/joystick/hidapi/SDL_hidapi_switch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ static SDL_bool BReadDeviceInfo(SDL_DriverSwitch_Context *ctx)
621621
ctx->m_eControllerType = (ESwitchDeviceInfoControllerType)reply->deviceInfo.ucDeviceType;
622622

623623
// Bytes 4-9: MAC address (big-endian)
624-
memcpy(ctx->m_rgucMACAddress, reply->deviceInfo.rgucMACAddress, sizeof(ctx->m_rgucMACAddress));
624+
SDL_memcpy(ctx->m_rgucMACAddress, reply->deviceInfo.rgucMACAddress, sizeof(ctx->m_rgucMACAddress));
625625

626626
return SDL_TRUE;
627627
}

src/joystick/hidapi/SDL_hidapijoystick.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ HIDAPI_UpdateDiscovery()
482482
if (buf.event.len > 0 &&
483483
!SDL_HIDAPI_discovery.m_bHaveDevicesChanged) {
484484
if (StrHasPrefix(buf.event.name, "hidraw") &&
485-
StrIsInteger(buf.event.name + strlen ("hidraw"))) {
485+
StrIsInteger(buf.event.name + SDL_strlen ("hidraw"))) {
486486
SDL_HIDAPI_discovery.m_bHaveDevicesChanged = SDL_TRUE;
487487
/* We found an hidraw change. We still continue to
488488
* drain the inotify fd to avoid leaving old
@@ -494,7 +494,7 @@ HIDAPI_UpdateDiscovery()
494494
remain -= len;
495495

496496
if (remain != 0) {
497-
memmove(&buf.storage[0], &buf.storage[len], remain);
497+
SDL_memmove(&buf.storage[0], &buf.storage[len], remain);
498498
}
499499
}
500500
}

src/joystick/linux/SDL_sysjoystick.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ LINUX_InotifyJoystickDetect(void)
529529
while (remain > 0) {
530530
if (buf.event.len > 0) {
531531
if (StrHasPrefix(buf.event.name, "event") &&
532-
StrIsInteger(buf.event.name + strlen ("event"))) {
532+
StrIsInteger(buf.event.name + SDL_strlen ("event"))) {
533533
char path[PATH_MAX];
534534

535535
SDL_snprintf(path, SDL_arraysize(path), "/dev/input/%s", buf.event.name);
@@ -547,7 +547,7 @@ LINUX_InotifyJoystickDetect(void)
547547
remain -= len;
548548

549549
if (remain != 0) {
550-
memmove (&buf.storage[0], &buf.storage[len], remain);
550+
SDL_memmove (&buf.storage[0], &buf.storage[len], remain);
551551
}
552552
}
553553
}

src/power/linux/SDL_syspower.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,17 @@ static const char *sys_class_power_supply_path = "/sys/class/power_supply";
4444
static int
4545
open_power_file(const char *base, const char *node, const char *key)
4646
{
47-
const size_t pathlen = strlen(base) + strlen(node) + strlen(key) + 3;
48-
char *path = (char *) alloca(pathlen);
47+
int fd;
48+
const size_t pathlen = SDL_strlen(base) + SDL_strlen(node) + SDL_strlen(key) + 3;
49+
char *path = SDL_stack_alloc(char, pathlen);
4950
if (path == NULL) {
5051
return -1; /* oh well. */
5152
}
5253

5354
snprintf(path, pathlen, "%s/%s/%s", base, node, key);
54-
return open(path, O_RDONLY | O_CLOEXEC);
55+
fd = open(path, O_RDONLY | O_CLOEXEC);
56+
SDL_stack_free(path);
57+
return fd;
5558
}
5659

5760

@@ -146,20 +149,20 @@ check_proc_acpi_battery(const char * node, SDL_bool * have_battery,
146149

147150
ptr = &state[0];
148151
while (make_proc_acpi_key_val(&ptr, &key, &val)) {
149-
if (strcmp(key, "present") == 0) {
150-
if (strcmp(val, "yes") == 0) {
152+
if (SDL_strcmp(key, "present") == 0) {
153+
if (SDL_strcmp(val, "yes") == 0) {
151154
*have_battery = SDL_TRUE;
152155
}
153-
} else if (strcmp(key, "charging state") == 0) {
156+
} else if (SDL_strcmp(key, "charging state") == 0) {
154157
/* !!! FIXME: what exactly _does_ charging/discharging mean? */
155-
if (strcmp(val, "charging/discharging") == 0) {
158+
if (SDL_strcmp(val, "charging/discharging") == 0) {
156159
charge = SDL_TRUE;
157-
} else if (strcmp(val, "charging") == 0) {
160+
} else if (SDL_strcmp(val, "charging") == 0) {
158161
charge = SDL_TRUE;
159162
}
160-
} else if (strcmp(key, "remaining capacity") == 0) {
163+
} else if (SDL_strcmp(key, "remaining capacity") == 0) {
161164
char *endptr = NULL;
162-
const int cvt = (int) strtol(val, &endptr, 10);
165+
const int cvt = (int) SDL_strtol(val, &endptr, 10);
163166
if (*endptr == ' ') {
164167
remaining = cvt;
165168
}
@@ -168,9 +171,9 @@ check_proc_acpi_battery(const char * node, SDL_bool * have_battery,
168171

169172
ptr = &info[0];
170173
while (make_proc_acpi_key_val(&ptr, &key, &val)) {
171-
if (strcmp(key, "design capacity") == 0) {
174+
if (SDL_strcmp(key, "design capacity") == 0) {
172175
char *endptr = NULL;
173-
const int cvt = (int) strtol(val, &endptr, 10);
176+
const int cvt = (int) SDL_strtol(val, &endptr, 10);
174177
if (*endptr == ' ') {
175178
maximum = cvt;
176179
}
@@ -225,8 +228,8 @@ check_proc_acpi_ac_adapter(const char * node, SDL_bool * have_ac)
225228

226229
ptr = &state[0];
227230
while (make_proc_acpi_key_val(&ptr, &key, &val)) {
228-
if (strcmp(key, "state") == 0) {
229-
if (strcmp(val, "on-line") == 0) {
231+
if (SDL_strcmp(key, "state") == 0) {
232+
if (SDL_strcmp(val, "on-line") == 0) {
230233
*have_ac = SDL_TRUE;
231234
}
232235
}
@@ -315,7 +318,7 @@ static SDL_bool
315318
int_string(char *str, int *val)
316319
{
317320
char *endptr = NULL;
318-
*val = (int) strtol(str, &endptr, 0);
321+
*val = (int) SDL_strtol(str, &endptr, 0);
319322
return ((*str != '\0') && (*endptr == '\0'));
320323
}
321324

@@ -377,8 +380,8 @@ SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState * state,
377380
if (!next_string(&ptr, &str)) { /* remaining battery life percent */
378381
return SDL_FALSE;
379382
}
380-
if (str[strlen(str) - 1] == '%') {
381-
str[strlen(str) - 1] = '\0';
383+
if (str[SDL_strlen(str) - 1] == '%') {
384+
str[SDL_strlen(str) - 1] = '\0';
382385
}
383386
if (!int_string(str, &battery_percent)) {
384387
return SDL_FALSE;
@@ -392,7 +395,7 @@ SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState * state,
392395

393396
if (!next_string(&ptr, &str)) { /* remaining battery life time units */
394397
return SDL_FALSE;
395-
} else if (strcmp(str, "min") == 0) {
398+
} else if (SDL_strcmp(str, "min") == 0) {
396399
battery_time *= 60;
397400
}
398401

src/video/kmsdrm/SDL_kmsdrmvideo.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,12 @@ static int get_dricount(void)
141141

142142
if (!(stat(KMSDRM_DRI_PATH, &sb) == 0
143143
&& S_ISDIR(sb.st_mode))) {
144-
printf("The path %s cannot be opened or is not available\n",
145-
KMSDRM_DRI_PATH);
144+
/*printf("The path %s cannot be opened or is not available\n", KMSDRM_DRI_PATH);*/
146145
return 0;
147146
}
148147

149148
if (access(KMSDRM_DRI_PATH, F_OK) == -1) {
150-
printf("The path %s cannot be opened\n",
151-
KMSDRM_DRI_PATH);
149+
/*printf("The path %s cannot be opened\n", KMSDRM_DRI_PATH);*/
152150
return 0;
153151
}
154152

src/video/kmsdrm/SDL_kmsdrmvulkan.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -437,18 +437,18 @@ SDL_bool KMSDRM_Vulkan_CreateSurface(_THIS,
437437
}
438438

439439
/* Get the list of displays supported by this plane. */
440-
supported_displays = (VkDisplayKHR*)malloc(sizeof(VkDisplayKHR) * supported_displays_count);
440+
supported_displays = (VkDisplayKHR*)SDL_malloc(sizeof(VkDisplayKHR) * supported_displays_count);
441441
vkGetDisplayPlaneSupportedDisplaysKHR(gpu, i,
442442
&supported_displays_count, supported_displays);
443443

444-
/* The plane must be bound to the chosen display, or not in use.
444+
/* The plane must be bound to the chosen display, or not in use.
445445
If none of these is true, iterate to another plane. */
446-
if (!((plane_props[i].currentDisplay == display) ||
447-
(plane_props[i].currentDisplay == VK_NULL_HANDLE)))
446+
if (!((plane_props[i].currentDisplay == display) ||
447+
(plane_props[i].currentDisplay == VK_NULL_HANDLE)))
448448
continue;
449449

450-
/* Iterate the list of displays supported by this plane
451-
in order to find out if the chosen display is among them. */
450+
/* Iterate the list of displays supported by this plane
451+
in order to find out if the chosen display is among them. */
452452
plane_supports_display = SDL_FALSE;
453453
for (j = 0; j < supported_displays_count; j++) {
454454
if (supported_displays[j] == display) {
@@ -457,9 +457,10 @@ SDL_bool KMSDRM_Vulkan_CreateSurface(_THIS,
457457
}
458458
}
459459

460-
/* Free the list of displays supported by this plane. */
461-
if (supported_displays)
462-
free(supported_displays);
460+
/* Free the list of displays supported by this plane. */
461+
if (supported_displays) {
462+
SDL_free(supported_displays);
463+
}
463464

464465
/* If the display is not supported by this plane, iterate to the next plane. */
465466
if (!plane_supports_display) {
@@ -469,9 +470,9 @@ SDL_bool KMSDRM_Vulkan_CreateSurface(_THIS,
469470
/* Want a plane that supports the alpha mode we have chosen. */
470471
vkGetDisplayPlaneCapabilitiesKHR(gpu, display_mode, i, &plane_caps);
471472
if (plane_caps.supportedAlpha == alpha_mode) {
472-
/* Yep, this plane is alright. */
473-
plane = i;
474-
break;
473+
/* Yep, this plane is alright. */
474+
plane = i;
475+
break;
475476
}
476477
}
477478

0 commit comments

Comments
 (0)