mirror of
https://github.com/vsergeev/c-periphery.git
synced 2026-08-18 02:54:54 +08:00
all: zero-initialize buf for strerror_r() in error formatters
some older implementations of strerror_r() may not populate buf. see issue #53.
This commit is contained in:
+1
-1
@@ -85,7 +85,7 @@ inline static int _gpio_error(gpio_t *gpio, int code, int c_errno, const char *f
|
||||
|
||||
/* Tack on strerror() and errno */
|
||||
if (c_errno) {
|
||||
char buf[64];
|
||||
char buf[64] = {0};
|
||||
strerror_r(c_errno, buf, sizeof(buf));
|
||||
snprintf(gpio->error.errmsg+strlen(gpio->error.errmsg), sizeof(gpio->error.errmsg)-strlen(gpio->error.errmsg), ": %s [errno %d]", buf, c_errno);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ static int _i2c_error(i2c_t *i2c, int code, int c_errno, const char *fmt, ...) {
|
||||
|
||||
/* Tack on strerror() and errno */
|
||||
if (c_errno) {
|
||||
char buf[64];
|
||||
char buf[64] = {0};
|
||||
strerror_r(c_errno, buf, sizeof(buf));
|
||||
snprintf(i2c->error.errmsg+strlen(i2c->error.errmsg), sizeof(i2c->error.errmsg)-strlen(i2c->error.errmsg), ": %s [errno %d]", buf, c_errno);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ static int _led_error(led_t *led, int code, int c_errno, const char *fmt, ...) {
|
||||
|
||||
/* Tack on strerror() and errno */
|
||||
if (c_errno) {
|
||||
char buf[64];
|
||||
char buf[64] = {0};
|
||||
strerror_r(c_errno, buf, sizeof(buf));
|
||||
snprintf(led->error.errmsg+strlen(led->error.errmsg), sizeof(led->error.errmsg)-strlen(led->error.errmsg), ": %s [errno %d]", buf, c_errno);
|
||||
}
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ static int _mmio_error(mmio_t *mmio, int code, int c_errno, const char *fmt, ...
|
||||
|
||||
/* Tack on strerror() and errno */
|
||||
if (c_errno) {
|
||||
char buf[64];
|
||||
char buf[64] = {0};
|
||||
strerror_r(c_errno, buf, sizeof(buf));
|
||||
snprintf(mmio->error.errmsg+strlen(mmio->error.errmsg), sizeof(mmio->error.errmsg)-strlen(mmio->error.errmsg), ": %s [errno %d]", buf, c_errno);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ static int _pwm_error(pwm_t *pwm, int code, int c_errno, const char *fmt, ...) {
|
||||
|
||||
/* Tack on strerror() and errno */
|
||||
if (c_errno) {
|
||||
char buf[64];
|
||||
char buf[64] = {0};
|
||||
strerror_r(c_errno, buf, sizeof(buf));
|
||||
snprintf(pwm->error.errmsg+strlen(pwm->error.errmsg), sizeof(pwm->error.errmsg)-strlen(pwm->error.errmsg), ": %s [errno %d]", buf, c_errno);
|
||||
}
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ static int _serial_error(serial_t *serial, int code, int c_errno, const char *fm
|
||||
|
||||
/* Tack on strerror() and errno */
|
||||
if (c_errno) {
|
||||
char buf[64];
|
||||
char buf[64] = {0};
|
||||
strerror_r(c_errno, buf, sizeof(buf));
|
||||
snprintf(serial->error.errmsg+strlen(serial->error.errmsg), sizeof(serial->error.errmsg)-strlen(serial->error.errmsg), ": %s [errno %d]", buf, c_errno);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ static int _spi_error(spi_t *spi, int code, int c_errno, const char *fmt, ...) {
|
||||
|
||||
/* Tack on strerror() and errno */
|
||||
if (c_errno) {
|
||||
char buf[64];
|
||||
char buf[64] = {0};
|
||||
strerror_r(c_errno, buf, sizeof(buf));
|
||||
snprintf(spi->error.errmsg+strlen(spi->error.errmsg), sizeof(spi->error.errmsg)-strlen(spi->error.errmsg), ": %s [errno %d]", buf, c_errno);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user