Skip to content

Commit 7a7616d

Browse files
committed
Use restrict keyword for format and message strings
The standard C functions called have undefined behavior if restrict is not met, so we should add them to functions calling vsnprintf and other related functions just in case.
1 parent 6242e80 commit 7a7616d

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

src/event/event_epoll.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ _dispatch_unote_resume_muxed(dispatch_unote_t du)
306306
dispatch_assert(_dispatch_unote_registered(du));
307307
uint32_t events = _dispatch_unote_required_events(du);
308308

309-
if (events & dmn->dmn_disarmed_events) {
309+
if (dmn->dmn_disarmed_events & events) {
310310
dmn->dmn_disarmed_events &= ~events;
311311
events = _dispatch_muxnote_armed_events(dmn);
312312
_dispatch_epoll_update(dmn, events, EPOLL_CTL_MOD);

src/init.c

+15-15
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ _dispatch_get_build(void)
896896
#if HAVE_OS_FAULT_WITH_PAYLOAD
897897
__attribute__((__format__(__printf__,2,3)))
898898
static void
899-
_dispatch_fault(const char *reason, const char *fmt, ...)
899+
_dispatch_fault(const char *restrict reason, const char *restrict fmt, ...)
900900
{
901901
char buf[1024];
902902
va_list ap;
@@ -1183,7 +1183,7 @@ _dispatch_log_file(char *buf, size_t len)
11831183

11841184
DISPATCH_NOINLINE
11851185
static void
1186-
_dispatch_logv_file(const char *msg, va_list ap)
1186+
_dispatch_logv_file(const char *restrict msg, va_list ap)
11871187
{
11881188
char buf[2048];
11891189
size_t bufsiz = sizeof(buf), offset = 0;
@@ -1204,13 +1204,13 @@ _dispatch_logv_file(const char *msg, va_list ap)
12041204

12051205
#if DISPATCH_USE_SIMPLE_ASL
12061206
static inline void
1207-
_dispatch_syslog(const char *msg)
1207+
_dispatch_syslog(const char *restrict msg)
12081208
{
12091209
_simple_asl_log(ASL_LEVEL_NOTICE, "com.apple.libsystem.libdispatch", msg);
12101210
}
12111211

12121212
static inline void
1213-
_dispatch_vsyslog(const char *msg, va_list ap)
1213+
_dispatch_vsyslog(const char *restrict msg, va_list ap)
12141214
{
12151215
char *str;
12161216
vasprintf(&str, msg, ap);
@@ -1221,13 +1221,13 @@ _dispatch_vsyslog(const char *msg, va_list ap)
12211221
}
12221222
#elif defined(_WIN32)
12231223
static inline void
1224-
_dispatch_syslog(const char *msg)
1224+
_dispatch_syslog(const char *restrict msg)
12251225
{
12261226
OutputDebugStringA(msg);
12271227
}
12281228

12291229
static inline void
1230-
_dispatch_vsyslog(const char *msg, va_list ap)
1230+
_dispatch_vsyslog(const char *restrict msg, va_list ap)
12311231
{
12321232
va_list argp;
12331233

@@ -1251,21 +1251,21 @@ _dispatch_vsyslog(const char *msg, va_list ap)
12511251
}
12521252
#else // DISPATCH_USE_SIMPLE_ASL
12531253
static inline void
1254-
_dispatch_syslog(const char *msg)
1254+
_dispatch_syslog(const char *restrict msg)
12551255
{
12561256
syslog(LOG_NOTICE, "%s", msg);
12571257
}
12581258

12591259
static inline void
1260-
_dispatch_vsyslog(const char *msg, va_list ap)
1260+
_dispatch_vsyslog(const char *restrict msg, va_list ap)
12611261
{
12621262
vsyslog(LOG_NOTICE, msg, ap);
12631263
}
12641264
#endif // DISPATCH_USE_SIMPLE_ASL
12651265

12661266
DISPATCH_ALWAYS_INLINE
12671267
static inline void
1268-
_dispatch_logv(const char *msg, size_t len, va_list *ap_ptr)
1268+
_dispatch_logv(const char *restrict msg, size_t len, va_list *restrict ap_ptr)
12691269
{
12701270
dispatch_once_f(&_dispatch_logv_pred, NULL, _dispatch_logv_init);
12711271
if (unlikely(dispatch_log_disabled)) {
@@ -1285,7 +1285,7 @@ _dispatch_logv(const char *msg, size_t len, va_list *ap_ptr)
12851285

12861286
DISPATCH_NOINLINE
12871287
void
1288-
_dispatch_log(const char *msg, ...)
1288+
_dispatch_log(const char *restrict msg, ...)
12891289
{
12901290
va_list ap;
12911291

@@ -1300,15 +1300,15 @@ _dispatch_log(const char *msg, ...)
13001300
#pragma mark dispatch_debug
13011301

13021302
static size_t
1303-
_dispatch_object_debug2(dispatch_object_t dou, char* buf, size_t bufsiz)
1303+
_dispatch_object_debug2(dispatch_object_t dou, char*restrict buf, size_t bufsiz)
13041304
{
13051305
DISPATCH_OBJECT_TFB(_dispatch_objc_debug, dou, buf, bufsiz);
13061306
return dx_debug(dou._do, buf, bufsiz);
13071307
}
13081308

13091309
DISPATCH_NOINLINE
13101310
static void
1311-
_dispatch_debugv(dispatch_object_t dou, const char *msg, va_list ap)
1311+
_dispatch_debugv(dispatch_object_t dou, const char *restrict msg, va_list ap)
13121312
{
13131313
char buf[2048];
13141314
size_t bufsiz = sizeof(buf), offset = 0;
@@ -1341,14 +1341,14 @@ _dispatch_debugv(dispatch_object_t dou, const char *msg, va_list ap)
13411341

13421342
DISPATCH_NOINLINE
13431343
void
1344-
dispatch_debugv(dispatch_object_t dou, const char *msg, va_list ap)
1344+
dispatch_debugv(dispatch_object_t dou, const char *restrict msg, va_list ap)
13451345
{
13461346
_dispatch_debugv(dou, msg, ap);
13471347
}
13481348

13491349
DISPATCH_NOINLINE
13501350
void
1351-
dispatch_debug(dispatch_object_t dou, const char *msg, ...)
1351+
dispatch_debug(dispatch_object_t dou, const char *restrict msg, ...)
13521352
{
13531353
va_list ap;
13541354

@@ -1360,7 +1360,7 @@ dispatch_debug(dispatch_object_t dou, const char *msg, ...)
13601360
#if DISPATCH_DEBUG
13611361
DISPATCH_NOINLINE
13621362
void
1363-
_dispatch_object_debug(dispatch_object_t dou, const char *msg, ...)
1363+
_dispatch_object_debug(dispatch_object_t dou, const char *restrict msg, ...)
13641364
{
13651365
va_list ap;
13661366

src/object.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ - (void)_dispose {
273273
[desc getBytes:buf maxLength:bufsiz-1 usedLength:&offset
274274
encoding:NSUTF8StringEncoding options:(NSStringEncodingConversionOptions)0
275275
range:NSMakeRange(0, [desc length]) remainingRange:NULL];
276-
if (offset) buf[offset] = 0;
276+
if (offset) buf[offset] = '\0';
277277
return offset;
278278
}
279279

0 commit comments

Comments
 (0)