fix: move declarations before statements for C89 compliance (#408)

net-snmp 5.9.5 injects `-Werror=declaration-after-statement` via
`net-snmp-config --cflags`, breaking builds on FreeBSD and other
systems where net-snmp is compiled with strict C89 flags.

Moves all variable declarations to the top of their enclosing
block in `spine.c` (main) and `util.c` (read_config_options,
spine_log, strncopy, checkAsRoot, regex_replace).

Verified: clean compile with `-Werror=declaration-after-statement`
across sql.c, spine.c, and util.c.

Supersedes #407 (which stripped the flag instead of fixing the root
cause).

Resolves #406

---------

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
This commit is contained in:
Thomas Vincent authored and GitHub committed 2026-03-01 11:36:14 -05:00
1 parent c1aa603a1b
commit 45f80f05de
4 files changed
+59 -39

No files matched your search

+8 -4
View File
@@ -122,6 +122,7 @@ void *snmp_host_init(int host_id, char *hostname, int snmp_version, char *snmp_c
void *sessp = NULL;
struct snmp_session session;
char hostnameport[BUFSIZE];
size_t len;
char *Apsz = NULL;
char *Xpsz = NULL;
@@ -133,7 +134,7 @@ void *snmp_host_init(int host_id, char *hostname, int snmp_version, char *snmp_c
snmp_sess_init(&session);
/* Bind to snmp_clientaddr if specified */
size_t len = strlen(set.snmp_clientaddr);
len = strlen(set.snmp_clientaddr);
if (len > 0 && len <= SMALL_BUFSIZE) {
#if SNMP_LOCALNAME == 1
session.localname = strdup(set.snmp_clientaddr);
@@ -217,10 +218,12 @@ void *snmp_host_init(int host_id, char *hostname, int snmp_version, char *snmp_c
}
/* set the authentication protocol */
int auth_type = usm_lookup_auth_type(snmp_auth_protocol);
if (auth_type > 0) {
const oid *auth_proto;
{
int auth_type;
const oid *auth_proto;
auth_type = usm_lookup_auth_type(snmp_auth_protocol);
if (auth_type > 0) {
auth_proto = sc_get_auth_oid(auth_type, &session.securityAuthProtoLen);
free(session.securityAuthProto);
session.securityAuthProto = snmp_duplicate_objid(auth_proto, session.securityAuthProtoLen);
@@ -339,6 +342,7 @@ void *snmp_host_init(int host_id, char *hostname, int snmp_version, char *snmp_c
}
SPINE_LOG_MEDIUM(("Device[%i] SNMPv3 Using AuthProto: %s, PrivProto: %s", host_id, snmp_auth_protocol, snmp_priv_protocol));
} /* end auth/priv block */
}
/* open SNMP Session */