mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-06-24 01:03:39 +00:00
Reimplement WHY() macro without comma operator
GCC 4.9 and later warn about unused values produced by the comma operator. Since the -Wno-unused-value option was removed from the non-Android Makefile.in, it will not compile the WHY() macro and its variants, with the -Wall option. This commit removes the comma operator from the WHY() macro and its variants, and replaces it with a new inline wrapper function. This commit also removes the WHYNULL() macro and fixes the three places it was used.
This commit is contained in:
12
keyring.c
12
keyring.c
@ -1546,8 +1546,10 @@ struct keypair *keyring_find_sas_private(keyring_file *k, keyring_identity *iden
|
||||
assert(identity);
|
||||
|
||||
keypair *kp = keyring_identity_keytype(identity, KEYTYPE_CRYPTOSIGN);
|
||||
if (kp==NULL)
|
||||
RETURN(WHYNULL("Identity lacks SAS"));
|
||||
if (kp==NULL) {
|
||||
WHY("Identity lacks SAS");
|
||||
RETURN(NULL);
|
||||
}
|
||||
|
||||
if (!kp->verified){
|
||||
if (!rhizome_verify_bundle_privatekey(kp->private_key,kp->public_key)){
|
||||
@ -1990,8 +1992,10 @@ unsigned char *keyring_get_nm_bytes(const sid_t *known_sidp, const sid_t *unknow
|
||||
in fact a known key */
|
||||
keyring_iterator it;
|
||||
keyring_iterator_start(keyring, &it);
|
||||
if (!keyring_find_sid(&it, known_sidp))
|
||||
RETURN(WHYNULL("known key is not in fact known."));
|
||||
if (!keyring_find_sid(&it, known_sidp)) {
|
||||
WHY("known key is not in fact known.");
|
||||
RETURN(NULL);
|
||||
}
|
||||
|
||||
/* work out where to store it */
|
||||
if (nm_slots_used<NM_CACHE_SLOTS) {
|
||||
|
19
log.h
19
log.h
@ -70,13 +70,20 @@ __SERVAL_LOG_INLINE void logMessage(int level, struct __sourceloc whence, const
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
__SERVAL_LOG_INLINE int logErrorAndReturnNegativeOne(struct __sourceloc whence, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vlogMessage(LOG_LEVEL_ERROR, whence, fmt, ap);
|
||||
va_end(ap);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Useful logging primitive macros.
|
||||
#define LOGF(L,F,...) logMessage(L, __WHENCE__, F, ##__VA_ARGS__)
|
||||
#define LOGF_perror(L,F,...) logMessage_perror(L, __WHENCE__, F, ##__VA_ARGS__)
|
||||
#define LOGF_perror(L,F,...) logMessage(L, __WHENCE__, F ": %s [errno=%d]", ##__VA_ARGS__, strerror(errno), errno)
|
||||
#define LOG_perror(L,X) LOGF_perror(L, "%s", (X))
|
||||
|
||||
#define logMessage_perror(L,whence,F,...) (logMessage(L, whence, F ": %s [errno=%d]", ##__VA_ARGS__, strerror(errno), errno))
|
||||
|
||||
#define NOWHENCE(LOGSTMT) do { const struct __sourceloc __whence = __NOWHENCE__; LOGSTMT; } while (0)
|
||||
|
||||
#define BACKTRACE logBacktrace(LOG_LEVEL_FATAL, __WHENCE__)
|
||||
@ -86,11 +93,9 @@ __SERVAL_LOG_INLINE void logMessage(int level, struct __sourceloc whence, const
|
||||
#define FATALF_perror(F,...) FATALF(F ": %s [errno=%d]", ##__VA_ARGS__, strerror(errno), errno)
|
||||
#define FATAL_perror(X) FATALF_perror("%s", (X))
|
||||
|
||||
#define WHYF(F,...) (LOGF(LOG_LEVEL_ERROR, F, ##__VA_ARGS__), -1)
|
||||
#define WHYF(F,...) logErrorAndReturnNegativeOne(__WHENCE__, F, ##__VA_ARGS__)
|
||||
#define WHY(X) WHYF("%s", (X))
|
||||
#define WHYFNULL(F,...) (LOGF(LOG_LEVEL_ERROR, F, ##__VA_ARGS__), NULL)
|
||||
#define WHYNULL(X) (WHYFNULL("%s", (X)))
|
||||
#define WHYF_perror(F,...) (LOGF_perror(LOG_LEVEL_ERROR, F, ##__VA_ARGS__), -1)
|
||||
#define WHYF_perror(F,...) WHYF(F ": %s [errno=%d]", ##__VA_ARGS__, strerror(errno), errno)
|
||||
#define WHY_perror(X) WHYF_perror("%s", (X))
|
||||
#define WHY_argv(X,ARGC,ARGV) logArgv(LOG_LEVEL_ERROR, __WHENCE__, (X), (ARGC), (ARGV))
|
||||
|
||||
|
@ -92,8 +92,10 @@ static const char *_rhizome_manifest_set(struct __sourceloc __whence, rhizome_ma
|
||||
m->values[i] = ret;
|
||||
return ret;
|
||||
}
|
||||
if (m->var_count >= NELS(m->vars))
|
||||
return WHYNULL("no more manifest vars");
|
||||
if (m->var_count >= NELS(m->vars)) {
|
||||
WHY("no more manifest vars");
|
||||
return NULL;
|
||||
}
|
||||
if ((m->vars[m->var_count] = str_edup(var)) == NULL)
|
||||
return NULL;
|
||||
const char *ret = m->values[m->var_count] = str_edup(value);
|
||||
|
Reference in New Issue
Block a user