Skip to content

Commit 553d363

Browse files
committed
Updates
1 parent db0ddbe commit 553d363

9 files changed

Lines changed: 214 additions & 150 deletions

File tree

compat/compat_ifaddrs.c

Lines changed: 135 additions & 100 deletions
Large diffs are not rendered by default.

features/features_cpu.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,7 @@ static void cpulist_parse(CpuList* list, char **buf, ssize_t length)
424424
q = end;
425425

426426
/* Get first value */
427-
p = parse_decimal(p, q, &start_value);
428-
if (p == NULL)
427+
if (!(p = parse_decimal(p, q, &start_value)))
429428
return;
430429

431430
end_value = start_value;
@@ -435,8 +434,7 @@ static void cpulist_parse(CpuList* list, char **buf, ssize_t length)
435434
*/
436435
if (p < q && *p == '-')
437436
{
438-
p = parse_decimal(p+1, q, &end_value);
439-
if (p == NULL)
437+
if (!(p = parse_decimal(p+1, q, &end_value)))
440438
return;
441439
}
442440

file/config_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,7 @@ static void test_config_file_parse_contains(
11621162
if (!val)
11631163
return;
11641164

1165-
if (out == NULL)
1165+
if (!out)
11661166
out = strdup("");
11671167
if (strcmp(out, val) != 0)
11681168
abort();

formats/cdfs/cdfs.c

Lines changed: 65 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ static void cdfs_determine_sector_size(cdfs_track_t* track)
6363

6464
static void cdfs_seek_track_sector(cdfs_track_t* track, unsigned int sector)
6565
{
66-
intfstream_seek(track->stream, sector * track->stream_sector_size + track->stream_sector_header_size + track->first_sector_offset, SEEK_SET);
66+
intfstream_seek(track->stream,
67+
sector * track->stream_sector_size +
68+
track->stream_sector_header_size +
69+
track->first_sector_offset, SEEK_SET);
6770
}
6871

6972
void cdfs_seek_sector(cdfs_file_t* file, unsigned int sector)
@@ -73,21 +76,21 @@ void cdfs_seek_sector(cdfs_file_t* file, unsigned int sector)
7376
{
7477
if (sector != file->current_sector)
7578
{
76-
file->current_sector = sector;
79+
file->current_sector = sector;
7780
file->sector_buffer_valid = 0;
7881
}
7982

80-
file->pos = file->current_sector * 2048;
81-
file->current_sector_offset = 0;
83+
file->pos = file->current_sector * 2048;
84+
file->current_sector_offset = 0;
8285
}
8386
}
8487

8588
static int cdfs_find_file(cdfs_file_t* file, const char* path)
8689
{
8790
uint8_t buffer[2048], *tmp;
8891
int sector, path_length;
89-
9092
const char* slash = strrchr(path, '\\');
93+
9194
if (slash)
9295
{
9396
/* navigate the path to the directory record for the file */
@@ -105,12 +108,13 @@ static int cdfs_find_file(cdfs_file_t* file, const char* path)
105108
{
106109
int offset;
107110

108-
/* find the cd information (always 16 frames in) */
111+
/* find the CD information (always 16 frames in) */
109112
cdfs_seek_track_sector(file->track, 16);
110113
intfstream_read(file->track->stream, buffer, sizeof(buffer));
111114

112115
/* the directory_record starts at 156 bytes into the sector.
113-
* the sector containing the root directory contents is a 3 byte value that is 2 bytes into the directory_record. */
116+
* the sector containing the root directory contents is a
117+
* 3 byte value that is 2 bytes into the directory_record. */
114118
offset = 156 + 2;
115119
sector = buffer[offset] | (buffer[offset + 1] << 8) | (buffer[offset + 2] << 16);
116120
}
@@ -120,21 +124,26 @@ static int cdfs_find_file(cdfs_file_t* file, const char* path)
120124
intfstream_read(file->track->stream, buffer, sizeof(buffer));
121125

122126
path_length = strlen(path);
123-
tmp = buffer;
127+
tmp = buffer;
128+
124129
while (tmp < buffer + sizeof(buffer))
125130
{
126-
/* the first byte of the record is the length of the record - if 0, we reached the end of the data */
131+
/* The first byte of the record is the length of
132+
* the record - if 0, we reached the end of the data */
127133
if (!*tmp)
128134
break;
129135

130-
/* filename is 33 bytes into the record and the format is "FILENAME;version" or "DIRECTORY" */
136+
/* filename is 33 bytes into the record and
137+
* the format is "FILENAME;version" or "DIRECTORY" */
131138
if ((tmp[33 + path_length] == ';' || tmp[33 + path_length] == '\0') &&
132139
strncasecmp((const char*)(tmp + 33), path, path_length) == 0)
133140
{
134141
/* the file size is in bytes 10-13 of the record */
135-
file->size = tmp[10] | (tmp[11] << 8) | (tmp[12] << 16) | (tmp[13] << 24);
142+
file->size = tmp[10] | (tmp[11] << 8)
143+
| (tmp[12] << 16) | (tmp[13] << 24);
136144

137-
/* the file contents are in the sector identified in bytes 2-4 of the record */
145+
/* the file contents are in the sector identified
146+
* in bytes 2-4 of the record */
138147
sector = tmp[2] | (tmp[3] << 8) | (tmp[4] << 16);
139148
return sector;
140149
}
@@ -153,15 +162,17 @@ int cdfs_open_file(cdfs_file_t* file, cdfs_track_t* track, const char* path)
153162

154163
memset(file, 0, sizeof(*file));
155164

156-
file->track = track;
157-
165+
file->track = track;
158166
file->current_sector = -1;
167+
159168
if (path)
160169
file->first_sector = cdfs_find_file(file, path);
161170
else if (file->track->stream_sector_size)
162171
{
163172
file->first_sector = 0;
164-
file->size = (intfstream_get_size(file->track->stream) / file->track->stream_sector_size) * 2048;
173+
file->size = (intfstream_get_size(
174+
file->track->stream) / file->track->stream_sector_size)
175+
* 2048;
165176
}
166177
else
167178
file->first_sector = -1;
@@ -189,12 +200,14 @@ int64_t cdfs_read_file(cdfs_file_t* file, void* buffer, uint64_t len)
189200
{
190201
if (remaining >= len)
191202
{
192-
memcpy(buffer, &file->sector_buffer[file->current_sector_offset], len);
203+
memcpy(buffer,
204+
&file->sector_buffer[file->current_sector_offset], len);
193205
file->current_sector_offset += len;
194206
return len;
195207
}
196208

197-
memcpy(buffer, &file->sector_buffer[file->current_sector_offset], remaining);
209+
memcpy(buffer,
210+
&file->sector_buffer[file->current_sector_offset], remaining);
198211
buffer = (char*)buffer + remaining;
199212
bytes_read += remaining;
200213
len -= remaining;
@@ -204,11 +217,11 @@ int64_t cdfs_read_file(cdfs_file_t* file, void* buffer, uint64_t len)
204217

205218
++file->current_sector;
206219
file->current_sector_offset = 0;
207-
file->sector_buffer_valid = 0;
220+
file->sector_buffer_valid = 0;
208221
}
209222
else if (file->current_sector < file->first_sector)
210223
{
211-
file->current_sector = file->first_sector;
224+
file->current_sector = file->first_sector;
212225
file->current_sector_offset = 0;
213226
}
214227

@@ -217,8 +230,9 @@ int64_t cdfs_read_file(cdfs_file_t* file, void* buffer, uint64_t len)
217230
cdfs_seek_track_sector(file->track, file->current_sector);
218231
intfstream_read(file->track->stream, buffer, 2048);
219232

220-
buffer = (char*)buffer + 2048;
233+
buffer = (char*)buffer + 2048;
221234
bytes_read += 2048;
235+
222236
++file->current_sector;
223237

224238
len -= 2048;
@@ -243,7 +257,8 @@ void cdfs_close_file(cdfs_file_t* file)
243257
{
244258
if (file)
245259
{
246-
/* not really anything to do here, just clear out the first_sector so read() won't do anything */
260+
/* not really anything to do here, just
261+
* clear out the first_sector so read() won't do anything */
247262
file->first_sector = -1;
248263
}
249264
}
@@ -314,21 +329,26 @@ static void cdfs_skip_spaces(const char** ptr)
314329
++(*ptr);
315330
}
316331

317-
static cdfs_track_t* cdfs_wrap_stream(intfstream_t* stream, unsigned first_sector_offset)
332+
static cdfs_track_t* cdfs_wrap_stream(
333+
intfstream_t* stream, unsigned first_sector_offset)
318334
{
319-
cdfs_track_t* track;
335+
cdfs_track_t* track = NULL;
320336

321-
if (stream == NULL)
337+
if (!stream)
322338
return NULL;
323339

324-
track = (cdfs_track_t*)calloc(1, sizeof(*track));
325-
track->stream = stream;
340+
track = (cdfs_track_t*)
341+
calloc(1, sizeof(*track));
342+
track->stream = stream;
326343
track->first_sector_offset = first_sector_offset;
344+
327345
cdfs_determine_sector_size(track);
346+
328347
return track;
329348
}
330349

331-
static cdfs_track_t* cdfs_open_cue_track(const char* path, unsigned int track_index)
350+
static cdfs_track_t* cdfs_open_cue_track(
351+
const char* path, unsigned int track_index)
332352
{
333353
char* cue = NULL;
334354
const char* line = NULL;
@@ -442,10 +462,9 @@ static cdfs_track_t* cdfs_open_cue_track(const char* path, unsigned int track_in
442462

443463
if (found_track && index_number == 1)
444464
{
445-
if (strstr(current_track_path, "/") || strstr(current_track_path, "\\"))
446-
{
465+
if ( strstr(current_track_path, "/") ||
466+
strstr(current_track_path, "\\"))
447467
strncpy(track_path, current_track_path, sizeof(track_path));
448-
}
449468
else
450469
{
451470
fill_pathname_basedir(track_path, path, sizeof(track_path));
@@ -462,7 +481,10 @@ static cdfs_track_t* cdfs_open_cue_track(const char* path, unsigned int track_in
462481
if (string_is_empty(track_path))
463482
return NULL;
464483

465-
track = cdfs_wrap_stream(intfstream_open_file(track_path, RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE), track_offset);
484+
track = cdfs_wrap_stream(intfstream_open_file(
485+
track_path, RETRO_VFS_FILE_ACCESS_READ,
486+
RETRO_VFS_FILE_ACCESS_HINT_NONE), track_offset);
487+
466488
if (track && track->stream_sector_size == 0)
467489
{
468490
track->stream_sector_size = sector_size;
@@ -482,11 +504,14 @@ static cdfs_track_t* cdfs_open_chd_track(const char* path, int32_t track_index)
482504
intfstream_t* intf_stream;
483505
cdfs_track_t* track;
484506

485-
intf_stream = intfstream_open_chd_track(path, RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE, track_index);
507+
intf_stream = intfstream_open_chd_track(path,
508+
RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE,
509+
track_index);
486510
if (!intf_stream)
487511
return NULL;
488512

489-
track = cdfs_wrap_stream(intf_stream, intfstream_get_offset_to_start(intf_stream));
513+
track = cdfs_wrap_stream(intf_stream,
514+
intfstream_get_offset_to_start(intf_stream));
490515

491516
if (track && track->stream_sector_header_size == 0)
492517
{
@@ -502,7 +527,8 @@ static cdfs_track_t* cdfs_open_chd_track(const char* path, int32_t track_index)
502527
}
503528
#endif
504529

505-
struct cdfs_track_t* cdfs_open_track(const char* path, unsigned int track_index)
530+
struct cdfs_track_t* cdfs_open_track(const char* path,
531+
unsigned int track_index)
506532
{
507533
const char* ext = path_get_extension(path);
508534

@@ -538,8 +564,11 @@ cdfs_track_t* cdfs_open_raw_track(const char* path)
538564
{
539565
const char* ext = path_get_extension(path);
540566

541-
if (string_is_equal_noncase(ext, "bin") || string_is_equal_noncase(ext, "iso"))
542-
return cdfs_wrap_stream(intfstream_open_file(path, RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE), 0);
567+
if ( string_is_equal_noncase(ext, "bin") ||
568+
string_is_equal_noncase(ext, "iso"))
569+
return cdfs_wrap_stream(intfstream_open_file(path,
570+
RETRO_VFS_FILE_ACCESS_READ,
571+
RETRO_VFS_FILE_ACCESS_HINT_NONE), 0);
543572

544573
/* unsupported file type */
545574
return NULL;

formats/wav/rwav.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ enum rwav_state rwav_iterate(rwav_iterator_t *iter)
100100

101101
samples = malloc(rwav->subchunk2size);
102102

103-
if (samples == NULL)
103+
if (!samples)
104104
return RWAV_ITERATE_ERROR;
105105

106106
rwav->numchannels = data[22] | data[23] << 8;

include/array/dynarray.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -782,10 +782,12 @@ dg__dynarr_grow(void** arr, dg__dynarr_md* md, size_t itemsize, size_t min_neede
782782
DG_DYNARR_INLINE void
783783
dg__dynarr_init(void** p, dg__dynarr_md* md, void* buf, size_t buf_cap)
784784
{
785-
*p = buf;
786-
md->cnt = 0;
787-
if(buf == NULL) md->cap = 0;
788-
else md->cap = (DG__DYNARR_SIZE_T_MSB | buf_cap);
785+
*p = buf;
786+
md->cnt = 0;
787+
if(!buf)
788+
md->cap = 0;
789+
else
790+
md->cap = (DG__DYNARR_SIZE_T_MSB | buf_cap);
789791
}
790792

791793
DG_DYNARR_INLINE int
@@ -952,7 +954,7 @@ dg__dynarr_grow(void** arr, dg__dynarr_md* md, size_t itemsize, size_t min_neede
952954
else
953955
{
954956
void* p = DG_DYNARR_REALLOC(*arr, itemsize, md->cnt, newcap);
955-
if(p == NULL) DG_DYNARR_FREE(*arr); /* realloc failed, at least don't leak memory */
957+
if (!p) DG_DYNARR_FREE(*arr); /* realloc failed, at least don't leak memory */
956958
*arr = p;
957959
}
958960

net/net_socket_ssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ int ssl_socket_receive_all_blocking(void *state_data, void *data_, size_t size)
189189

190190
mbedtls_net_set_block(&state->net_ctx);
191191

192-
while (1)
192+
for (;;)
193193
{
194194
/* mbedtls_ssl_read wants non-const data but it only reads it, so this cast is safe */
195195
int ret = mbedtls_ssl_read(&state->ctx, (unsigned char*)data, size);

queues/task_queue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ static void threaded_worker(void *userdata)
451451

452452
/* Get first task to run */
453453
task = tasks_running.front;
454-
if (task == NULL)
454+
if (!task)
455455
{
456456
scond_wait(worker_cond, running_lock);
457457
slock_unlock(running_lock);

rthreads/tpool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ static void tpool_worker(void *arg)
144144
* Also, the working_cnt can't be changed (except the thread holding the lock).
145145
* At this point if there isn't any work processing and if there is no work
146146
* signal this is the case. */
147-
if (!tp->stop && tp->working_cnt == 0 && tp->work_first == NULL)
147+
if (!tp->stop && tp->working_cnt == 0 && !tp->work_first)
148148
scond_signal(tp->working_cond);
149149
slock_unlock(tp->work_mutex);
150150
}

0 commit comments

Comments
 (0)