Commit ed2b5816 authored by Vitaly Buka's avatar Vitaly Buka

Merge pull request #18 from jacobmarble/gnu

Fixes for gcc.
parents ffd61bcb 2e4662ce
......@@ -58,8 +58,12 @@ char *request(void *sessp, long max_repetitions, oid *name, size_t name_length,
if (status != STAT_SUCCESS) {
char *errstr = session_error(sessp);
char *err = NULL;
asprintf(&err, "SNMP request error: %s", errstr);
free(errstr);
int failure = asprintf(&err, "SNMP request error: %s", errstr);
if (failure == -1) {
err = errstr;
} else {
free(errstr);
}
return err;
}
......@@ -119,8 +123,12 @@ struct bulkwalk_response *bulkwalk(char *peername, char *community) {
if ((sessp = snmp_sess_open(&session)) == NULL) {
char *errstr = open_error(&session);
char *err = NULL;
asprintf(&err, "Open SNMP session error: %s", errstr);
free(errstr);
int failure = asprintf(&err, "Open SNMP session error: %s", errstr);
if (failure == -1) {
err = errstr;
} else {
free(errstr);
}
add_error(response, err);
return response;
}
......@@ -163,8 +171,12 @@ struct bulkwalk_response *bulkwalk(char *peername, char *community) {
char *errstr = session_error(sessp);
err = NULL;
asprintf(&err, "SNMP response error (%ld): %s", subtree->errstat, errstr);
free(errstr);
int failure = asprintf(&err, "SNMP response error (%ld): %s", subtree->errstat, errstr);
if (failure == -1) {
err = errstr;
} else {
free(errstr);
}
add_error(response, err);
snmp_free_pdu(subtree);
break;
......
......@@ -6,6 +6,13 @@ license that can be found in the LICENSE file or at
https://developers.google.com/open-source/licenses/bsd
*/
// This makes asprintf work properly under GNU.
#ifdef __GNUC__
# ifndef _GNU_SOURCE
# define _GNU_SOURCE
# endif // _GNU_SOURCE
#endif //__GNUC__
#include <stddef.h> // size_t
#include <stdio.h> // asprintf
#include <stdlib.h> // calloc, realloc, free
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment