Skip to content

Commit c7f6cd5

Browse files
authored
Merge pull request #847 from giuseppe/function-attributes
add some function attributes
2 parents e0d6caa + 8711fbd commit c7f6cd5

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

src/libcrun/container.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1683,7 +1683,7 @@ write_container_status (libcrun_container_t *container, libcrun_context_t *conte
16831683
.scope = NULL,
16841684
};
16851685

1686-
get_current_timestamp (created);
1686+
get_current_timestamp (created, sizeof (created));
16871687

16881688
if (cwd == NULL)
16891689
OOM ();

src/libcrun/error.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ int crun_error_release (libcrun_error_t *err);
7777

7878
void crun_error_write_warning_and_release (FILE *out, libcrun_error_t **err);
7979

80-
LIBCRUN_PUBLIC void libcrun_warning (const char *msg, ...);
80+
LIBCRUN_PUBLIC void libcrun_warning (const char *msg, ...) __attribute__ ((format (printf, 1, 2)));
8181

82-
LIBCRUN_PUBLIC void libcrun_error (int errno_, const char *msg, ...);
82+
LIBCRUN_PUBLIC void libcrun_error (int errno_, const char *msg, ...) __attribute__ ((format (printf, 2, 3)));
8383

84-
LIBCRUN_PUBLIC int libcrun_make_error (libcrun_error_t *err, int status, const char *msg, ...);
84+
LIBCRUN_PUBLIC int libcrun_make_error (libcrun_error_t *err, int status, const char *msg, ...) __attribute__ ((format (printf, 3, 4)));
8585

8686
LIBCRUN_PUBLIC void libcrun_error_write_warning_and_release (FILE *out, libcrun_error_t **err);
8787

src/libcrun/utils.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ mark_or_close_fds_ge_than (int n, bool close_now, libcrun_error_t *err)
16051605
}
16061606

16071607
void
1608-
get_current_timestamp (char *out)
1608+
get_current_timestamp (char *out, size_t len)
16091609
{
16101610
struct timeval tv;
16111611
struct tm now;
@@ -1615,7 +1615,8 @@ get_current_timestamp (char *out)
16151615
gmtime_r (&tv.tv_sec, &now);
16161616
strftime (timestamp, sizeof (timestamp), "%Y-%m-%dT%H:%M:%S", &now);
16171617

1618-
sprintf (out, "%s.%09ldZ", timestamp, tv.tv_usec);
1618+
snprintf (out, len, "%s.%09ldZ", timestamp, tv.tv_usec);
1619+
out[len - 1] = '\0';
16191620
}
16201621

16211622
int

src/libcrun/utils.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
#define LIKELY(x) __builtin_expect ((x), 1)
5555
#define UNLIKELY(x) __builtin_expect ((x), 0)
5656

57-
static inline void *
57+
__attribute__ ((malloc)) static inline void *
5858
xmalloc (size_t size)
5959
{
6060
void *res = malloc (size);
@@ -63,7 +63,7 @@ xmalloc (size_t size)
6363
return res;
6464
}
6565

66-
static inline void *
66+
__attribute__ ((malloc)) static inline void *
6767
xmalloc0 (size_t size)
6868
{
6969
void *res = calloc (1, size);
@@ -72,7 +72,7 @@ xmalloc0 (size_t size)
7272
return res;
7373
}
7474

75-
static inline void *
75+
__attribute__ ((malloc)) static inline void *
7676
xrealloc (void *ptr, size_t size)
7777
{
7878
void *res = realloc (ptr, size);
@@ -223,7 +223,7 @@ path_is_slash_dev (const char *path)
223223
return true;
224224
}
225225

226-
int xasprintf (char **str, const char *fmt, ...);
226+
int xasprintf (char **str, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
227227

228228
int crun_path_exists (const char *path, libcrun_error_t *err);
229229

@@ -302,7 +302,7 @@ int run_process_with_stdin_timeout_envp (char *path, char **args, const char *cw
302302

303303
int mark_or_close_fds_ge_than (int n, bool close_now, libcrun_error_t *err);
304304

305-
void get_current_timestamp (char *out);
305+
void get_current_timestamp (char *out, size_t len);
306306

307307
int set_blocking_fd (int fd, int blocking, libcrun_error_t *err);
308308

@@ -336,7 +336,7 @@ int safe_openat (int dirfd, const char *rootfs, size_t rootfs_len, const char *p
336336

337337
ssize_t safe_write (int fd, const void *buf, ssize_t count);
338338

339-
int append_paths (char **out, libcrun_error_t *err, ...);
339+
int append_paths (char **out, libcrun_error_t *err, ...) __attribute__ ((sentinel));
340340

341341
int str2sig (const char *name);
342342

0 commit comments

Comments
 (0)