Skip to content

Commit d895ee1

Browse files
alejandro-colomarhallyn
authored andcommitted
lib/: Use vaprintf() instead of vasprintf(3)
1 parent 86303b1 commit d895ee1

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

lib/selinux.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313

1414
#include <selinux/selinux.h>
1515
#include <selinux/label.h>
16-
#include "prototypes.h"
1716

17+
#include "prototypes.h"
1818
#include "shadowlog_internal.h"
19+
#include "string/sprintf/aprintf.h"
20+
1921

2022
static bool selinux_checked = false;
2123
static bool selinux_enabled;
@@ -113,18 +115,15 @@ format_attr(printf, 2, 3)
113115
static int selinux_log_cb (int type, const char *fmt, ...) {
114116
va_list ap;
115117
char *buf;
116-
int r;
117118
#ifdef WITH_AUDIT
118119
static int selinux_audit_fd = -2;
119120
#endif
120121

121122
va_start (ap, fmt);
122-
r = vasprintf (&buf, fmt, ap);
123+
buf = vaprintf(fmt, ap);
123124
va_end (ap);
124-
125-
if (r < 0) {
125+
if (buf == NULL)
126126
return 0;
127-
}
128127

129128
#ifdef WITH_AUDIT
130129
if (-2 == selinux_audit_fd) {

lib/semanage.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,23 @@
2323

2424
#include "attr.h"
2525
#include "prototypes.h"
26-
2726
#include "shadowlog_internal.h"
27+
#include "string/sprintf/aprintf.h"
2828

2929

3030
format_attr(printf, 3, 4)
3131
static void semanage_error_callback (MAYBE_UNUSED void *varg,
3232
semanage_handle_t *handle,
3333
const char *fmt, ...)
3434
{
35-
int ret;
3635
char * message = NULL;
3736
va_list ap;
3837

39-
4038
va_start (ap, fmt);
41-
ret = vasprintf (&message, fmt, ap);
39+
message = vaprintf(fmt, ap);
4240
va_end (ap);
43-
if (ret < 0) {
44-
/* ENOMEM */
41+
if (message == NULL)
4542
return;
46-
}
4743

4844
switch (semanage_msg_get_level (handle)) {
4945
case SEMANAGE_MSG_ERR:

0 commit comments

Comments
 (0)