Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fmt/print: snprintf restrict declarations #438

Merged
merged 3 commits into from
Jul 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions include/re_fmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ typedef int(re_printf_h)(struct re_printf *pf, void *arg);
int re_vhprintf(const char *fmt, va_list ap, re_vprintf_h *vph, void *arg);
int re_vfprintf(FILE *stream, const char *fmt, va_list ap);
int re_vprintf(const char *fmt, va_list ap);
int re_vsnprintf(char *str, size_t size, const char *fmt, va_list ap);
int re_vsnprintf(char *restrict str, size_t size, const char *restrict fmt,
va_list ap);
int re_vsdprintf(char **strp, const char *fmt, va_list ap);

int re_hprintf(struct re_printf *pf, const char *fmt, ...);
int re_fprintf(FILE *stream, const char *fmt, ...);
int re_printf(const char *fmt, ...);
int re_snprintf(char *str, size_t size, const char *fmt, ...);
int re_snprintf(char *restrict str, size_t size, const char *restrict fmt,
...);
int re_sdprintf(char **strp, const char *fmt, ...);


Expand Down
4 changes: 4 additions & 0 deletions include/re_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

#include <sys/types.h>

#ifdef __cplusplus
#define restrict
#endif

#ifdef _MSC_VER
#include <stdlib.h>

Expand Down
5 changes: 3 additions & 2 deletions src/fmt/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,8 @@ int re_vprintf(const char *fmt, va_list ap)
*
* @return The number of characters printed, or -1 if error
*/
int re_vsnprintf(char *str, size_t size, const char *fmt, va_list ap)
int re_vsnprintf(char *restrict str, size_t size, const char *restrict fmt,
va_list ap)
{
struct pl pl;
int err;
Expand Down Expand Up @@ -756,7 +757,7 @@ int re_printf(const char *fmt, ...)
*
* @return The number of characters printed, or -1 if error
*/
int re_snprintf(char *str, size_t size, const char *fmt, ...)
int re_snprintf(char *restrict str, size_t size, const char *restrict fmt, ...)
{
va_list ap;
int n;
Expand Down