Fixed some accidental uses of external C runtime functions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
diff --git a/src/audio/nas/SDL_nasaudio.c b/src/audio/nas/SDL_nasaudio.c
index 1f7ef90..1650726 100644
--- a/src/audio/nas/SDL_nasaudio.c
+++ b/src/audio/nas/SDL_nasaudio.c
@@ -113,11 +113,11 @@ LoadNASLibrary(void)
/* Copy error string so we can use it in a new SDL_SetError(). */
const char *origerr = SDL_GetError();
const size_t len = SDL_strlen(origerr) + 1;
- char *err = (char *) alloca(len);
+ char *err = SDL_stack_alloc(char, len);
SDL_strlcpy(err, origerr, len);
+ SDL_SetError("NAS: SDL_LoadObject('%s') failed: %s", nas_library, err);
+ SDL_stack_free(err);
retval = -1;
- SDL_SetError("NAS: SDL_LoadObject('%s') failed: %s",
- nas_library, err);
} else {
retval = load_nas_syms();
if (retval < 0) {
diff --git a/src/core/linux/SDL_evdev_kbd.c b/src/core/linux/SDL_evdev_kbd.c
index 4ea6b14..6792d8a 100644
--- a/src/core/linux/SDL_evdev_kbd.c
+++ b/src/core/linux/SDL_evdev_kbd.c
@@ -386,7 +386,7 @@ SDL_EVDEV_kbd_init(void)
}
/* Allow inhibiting keyboard mute with env. variable for debugging etc. */
- if (getenv("SDL_INPUT_LINUX_KEEP_KBD") == NULL) {
+ if (SDL_getenv("SDL_INPUT_LINUX_KEEP_KBD") == NULL) {
/* Mute the keyboard so keystrokes only generate evdev events
* and do not leak through to the console
*/
diff --git a/src/filesystem/unix/SDL_sysfilesystem.c b/src/filesystem/unix/SDL_sysfilesystem.c
index fa5beb8..c39c07a 100644
--- a/src/filesystem/unix/SDL_sysfilesystem.c
+++ b/src/filesystem/unix/SDL_sysfilesystem.c
@@ -245,7 +245,7 @@ SDL_GetBasePath(void)
if (retval != NULL) {
/* try to shrink buffer... */
- char *ptr = (char *) SDL_realloc(retval, strlen(retval) + 1);
+ char *ptr = (char *) SDL_realloc(retval, SDL_strlen(retval) + 1);
if (ptr != NULL)
retval = ptr; /* oh well if it failed. */
}
diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c
index b183ca7..555fd83 100644
--- a/src/haptic/linux/SDL_syshaptic.c
+++ b/src/haptic/linux/SDL_syshaptic.c
@@ -166,7 +166,7 @@ SDL_SYS_HapticInit(void)
i = 0;
for (j = 0; j < MAX_HAPTICS; ++j) {
- snprintf(path, PATH_MAX, joydev_pattern, i++);
+ SDL_snprintf(path, PATH_MAX, joydev_pattern, i++);
MaybeAddDevice(path);
}
diff --git a/src/joystick/hidapi/SDL_hidapi_switch.c b/src/joystick/hidapi/SDL_hidapi_switch.c
index 610bf35..70fa710 100644
--- a/src/joystick/hidapi/SDL_hidapi_switch.c
+++ b/src/joystick/hidapi/SDL_hidapi_switch.c
@@ -621,7 +621,7 @@ static SDL_bool BReadDeviceInfo(SDL_DriverSwitch_Context *ctx)
ctx->m_eControllerType = (ESwitchDeviceInfoControllerType)reply->deviceInfo.ucDeviceType;
// Bytes 4-9: MAC address (big-endian)
- memcpy(ctx->m_rgucMACAddress, reply->deviceInfo.rgucMACAddress, sizeof(ctx->m_rgucMACAddress));
+ SDL_memcpy(ctx->m_rgucMACAddress, reply->deviceInfo.rgucMACAddress, sizeof(ctx->m_rgucMACAddress));
return SDL_TRUE;
}
diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c
index 0aa850d..73b7ac9 100644
--- a/src/joystick/hidapi/SDL_hidapijoystick.c
+++ b/src/joystick/hidapi/SDL_hidapijoystick.c
@@ -482,7 +482,7 @@ HIDAPI_UpdateDiscovery()
if (buf.event.len > 0 &&
!SDL_HIDAPI_discovery.m_bHaveDevicesChanged) {
if (StrHasPrefix(buf.event.name, "hidraw") &&
- StrIsInteger(buf.event.name + strlen ("hidraw"))) {
+ StrIsInteger(buf.event.name + SDL_strlen ("hidraw"))) {
SDL_HIDAPI_discovery.m_bHaveDevicesChanged = SDL_TRUE;
/* We found an hidraw change. We still continue to
* drain the inotify fd to avoid leaving old
@@ -494,7 +494,7 @@ HIDAPI_UpdateDiscovery()
remain -= len;
if (remain != 0) {
- memmove(&buf.storage[0], &buf.storage[len], remain);
+ SDL_memmove(&buf.storage[0], &buf.storage[len], remain);
}
}
}
diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c
index 88aea57..984005f 100644
--- a/src/joystick/linux/SDL_sysjoystick.c
+++ b/src/joystick/linux/SDL_sysjoystick.c
@@ -529,7 +529,7 @@ LINUX_InotifyJoystickDetect(void)
while (remain > 0) {
if (buf.event.len > 0) {
if (StrHasPrefix(buf.event.name, "event") &&
- StrIsInteger(buf.event.name + strlen ("event"))) {
+ StrIsInteger(buf.event.name + SDL_strlen ("event"))) {
char path[PATH_MAX];
SDL_snprintf(path, SDL_arraysize(path), "/dev/input/%s", buf.event.name);
@@ -547,7 +547,7 @@ LINUX_InotifyJoystickDetect(void)
remain -= len;
if (remain != 0) {
- memmove (&buf.storage[0], &buf.storage[len], remain);
+ SDL_memmove (&buf.storage[0], &buf.storage[len], remain);
}
}
}
diff --git a/src/power/linux/SDL_syspower.c b/src/power/linux/SDL_syspower.c
index dee691d..f911005 100644
--- a/src/power/linux/SDL_syspower.c
+++ b/src/power/linux/SDL_syspower.c
@@ -44,14 +44,17 @@ static const char *sys_class_power_supply_path = "/sys/class/power_supply";
static int
open_power_file(const char *base, const char *node, const char *key)
{
- const size_t pathlen = strlen(base) + strlen(node) + strlen(key) + 3;
- char *path = (char *) alloca(pathlen);
+ int fd;
+ const size_t pathlen = SDL_strlen(base) + SDL_strlen(node) + SDL_strlen(key) + 3;
+ char *path = SDL_stack_alloc(char, pathlen);
if (path == NULL) {
return -1; /* oh well. */
}
snprintf(path, pathlen, "%s/%s/%s", base, node, key);
- return open(path, O_RDONLY | O_CLOEXEC);
+ fd = open(path, O_RDONLY | O_CLOEXEC);
+ SDL_stack_free(path);
+ return fd;
}
@@ -146,20 +149,20 @@ check_proc_acpi_battery(const char * node, SDL_bool * have_battery,
ptr = &state[0];
while (make_proc_acpi_key_val(&ptr, &key, &val)) {
- if (strcmp(key, "present") == 0) {
- if (strcmp(val, "yes") == 0) {
+ if (SDL_strcmp(key, "present") == 0) {
+ if (SDL_strcmp(val, "yes") == 0) {
*have_battery = SDL_TRUE;
}
- } else if (strcmp(key, "charging state") == 0) {
+ } else if (SDL_strcmp(key, "charging state") == 0) {
/* !!! FIXME: what exactly _does_ charging/discharging mean? */
- if (strcmp(val, "charging/discharging") == 0) {
+ if (SDL_strcmp(val, "charging/discharging") == 0) {
charge = SDL_TRUE;
- } else if (strcmp(val, "charging") == 0) {
+ } else if (SDL_strcmp(val, "charging") == 0) {
charge = SDL_TRUE;
}
- } else if (strcmp(key, "remaining capacity") == 0) {
+ } else if (SDL_strcmp(key, "remaining capacity") == 0) {
char *endptr = NULL;
- const int cvt = (int) strtol(val, &endptr, 10);
+ const int cvt = (int) SDL_strtol(val, &endptr, 10);
if (*endptr == ' ') {
remaining = cvt;
}
@@ -168,9 +171,9 @@ check_proc_acpi_battery(const char * node, SDL_bool * have_battery,
ptr = &info[0];
while (make_proc_acpi_key_val(&ptr, &key, &val)) {
- if (strcmp(key, "design capacity") == 0) {
+ if (SDL_strcmp(key, "design capacity") == 0) {
char *endptr = NULL;
- const int cvt = (int) strtol(val, &endptr, 10);
+ const int cvt = (int) SDL_strtol(val, &endptr, 10);
if (*endptr == ' ') {
maximum = cvt;
}
@@ -225,8 +228,8 @@ check_proc_acpi_ac_adapter(const char * node, SDL_bool * have_ac)
ptr = &state[0];
while (make_proc_acpi_key_val(&ptr, &key, &val)) {
- if (strcmp(key, "state") == 0) {
- if (strcmp(val, "on-line") == 0) {
+ if (SDL_strcmp(key, "state") == 0) {
+ if (SDL_strcmp(val, "on-line") == 0) {
*have_ac = SDL_TRUE;
}
}
@@ -315,7 +318,7 @@ static SDL_bool
int_string(char *str, int *val)
{
char *endptr = NULL;
- *val = (int) strtol(str, &endptr, 0);
+ *val = (int) SDL_strtol(str, &endptr, 0);
return ((*str != '\0') && (*endptr == '\0'));
}
@@ -377,8 +380,8 @@ SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState * state,
if (!next_string(&ptr, &str)) { /* remaining battery life percent */
return SDL_FALSE;
}
- if (str[strlen(str) - 1] == '%') {
- str[strlen(str) - 1] = '\0';
+ if (str[SDL_strlen(str) - 1] == '%') {
+ str[SDL_strlen(str) - 1] = '\0';
}
if (!int_string(str, &battery_percent)) {
return SDL_FALSE;
@@ -392,7 +395,7 @@ SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState * state,
if (!next_string(&ptr, &str)) { /* remaining battery life time units */
return SDL_FALSE;
- } else if (strcmp(str, "min") == 0) {
+ } else if (SDL_strcmp(str, "min") == 0) {
battery_time *= 60;
}
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c
index fbc2c96..95198fb 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.c
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c
@@ -141,14 +141,12 @@ static int get_dricount(void)
if (!(stat(KMSDRM_DRI_PATH, &sb) == 0
&& S_ISDIR(sb.st_mode))) {
- printf("The path %s cannot be opened or is not available\n",
- KMSDRM_DRI_PATH);
+ /*printf("The path %s cannot be opened or is not available\n", KMSDRM_DRI_PATH);*/
return 0;
}
if (access(KMSDRM_DRI_PATH, F_OK) == -1) {
- printf("The path %s cannot be opened\n",
- KMSDRM_DRI_PATH);
+ /*printf("The path %s cannot be opened\n", KMSDRM_DRI_PATH);*/
return 0;
}
diff --git a/src/video/kmsdrm/SDL_kmsdrmvulkan.c b/src/video/kmsdrm/SDL_kmsdrmvulkan.c
index 4e9d208..390271e 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvulkan.c
+++ b/src/video/kmsdrm/SDL_kmsdrmvulkan.c
@@ -437,18 +437,18 @@ SDL_bool KMSDRM_Vulkan_CreateSurface(_THIS,
}
/* Get the list of displays supported by this plane. */
- supported_displays = (VkDisplayKHR*)malloc(sizeof(VkDisplayKHR) * supported_displays_count);
+ supported_displays = (VkDisplayKHR*)SDL_malloc(sizeof(VkDisplayKHR) * supported_displays_count);
vkGetDisplayPlaneSupportedDisplaysKHR(gpu, i,
&supported_displays_count, supported_displays);
- /* The plane must be bound to the chosen display, or not in use.
+ /* The plane must be bound to the chosen display, or not in use.
If none of these is true, iterate to another plane. */
- if (!((plane_props[i].currentDisplay == display) ||
- (plane_props[i].currentDisplay == VK_NULL_HANDLE)))
+ if (!((plane_props[i].currentDisplay == display) ||
+ (plane_props[i].currentDisplay == VK_NULL_HANDLE)))
continue;
- /* Iterate the list of displays supported by this plane
- in order to find out if the chosen display is among them. */
+ /* Iterate the list of displays supported by this plane
+ in order to find out if the chosen display is among them. */
plane_supports_display = SDL_FALSE;
for (j = 0; j < supported_displays_count; j++) {
if (supported_displays[j] == display) {
@@ -457,9 +457,10 @@ SDL_bool KMSDRM_Vulkan_CreateSurface(_THIS,
}
}
- /* Free the list of displays supported by this plane. */
- if (supported_displays)
- free(supported_displays);
+ /* Free the list of displays supported by this plane. */
+ if (supported_displays) {
+ SDL_free(supported_displays);
+ }
/* If the display is not supported by this plane, iterate to the next plane. */
if (!plane_supports_display) {
@@ -469,9 +470,9 @@ SDL_bool KMSDRM_Vulkan_CreateSurface(_THIS,
/* Want a plane that supports the alpha mode we have chosen. */
vkGetDisplayPlaneCapabilitiesKHR(gpu, display_mode, i, &plane_caps);
if (plane_caps.supportedAlpha == alpha_mode) {
- /* Yep, this plane is alright. */
- plane = i;
- break;
+ /* Yep, this plane is alright. */
+ plane = i;
+ break;
}
}