Give every printf-like function restrict qualifiers

The format value has to be a string literal, every time.

Otherwise, you are not using these functions correctly. To reinforce this fact, I putrestrict over every non-contrib example of this I could find.
This commit is contained in:
Rose
2023-07-07 13:52:45 -04:00
parent 92860c717d
commit 5d758264ab
48 changed files with 143 additions and 143 deletions

View File

@@ -96,7 +96,7 @@ cleanup:
}
int
vsnprintf_append(char *output, size_t max_output_len, const char *fmt, va_list args)
vsnprintf_append(char * restrict output, size_t max_output_len, const char * restrict fmt, va_list args)
{
va_list args2;
va_copy(args2, args);
@@ -109,7 +109,7 @@ vsnprintf_append(char *output, size_t max_output_len, const char *fmt, va_list a
}
int
snprintf_append(char *output, size_t max_output_len, const char *fmt, ...)
snprintf_append(char * restrict output, size_t max_output_len, const char * restrict fmt, ...)
{
va_list args;
va_start(args, fmt);

View File

@@ -49,8 +49,8 @@ char *str_replaced(const char *string, size_t dest_length, const char *old, cons
// same, but "string" must be able to store 'max_length' number of characters including the null terminator
void str_replace_in_place(char *string, size_t max_length, const char *old, const char *new);
int vsnprintf_append(char *output, size_t max_output_len, const char *fmt, va_list args);
int snprintf_append(char *output, size_t max_output_len, const char *fmt, ...);
int vsnprintf_append(char * restrict output, size_t max_output_len, const char * restrict fmt, va_list args);
int snprintf_append(char * restrict output, size_t max_output_len, const char * restrict fmt, ...);
int str_array_count(char **str_array);
void str_array_snprint(char *out_str, size_t max_len, char **str_array, int array_len);

View File

@@ -193,7 +193,7 @@ fake_conversation_with_suspend(int num_msgs, const struct sudo_conv_message msgs
}
int
fake_printf(int msg_type, const char *fmt, ...)
fake_printf(int msg_type, const char * restrict fmt, ...)
{
int rc = -1;
va_list args;

View File

@@ -154,7 +154,7 @@ int fake_conversation(int num_msgs, const struct sudo_conv_message msgs[],
int fake_conversation_with_suspend(int num_msgs, const struct sudo_conv_message msgs[],
struct sudo_conv_reply replies[], struct sudo_conv_callback *callback);
int fake_printf(int msg_type, const char *fmt, ...);
int fake_printf(int msg_type, const char * restrict fmt, ...);
int verify_log_lines(const char *reference_path);