summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjirka-h <hladky.jiri@gmail.com>2020-07-01 02:44:22 +0200
committerGitHub <noreply@github.com>2020-07-01 02:44:22 +0200
commit7c164d70802b6d3433aab403811152f20e397260 (patch)
tree3642b7aa55160850d9304ecf02c38c0aa6ba21dc
parentRemoved haveged.spec - RPM spec files are stored in contrib/build directory (diff)
parentUse labs() (diff)
downloadhaveged-7c164d70802b6d3433aab403811152f20e397260.tar.xz
haveged-7c164d70802b6d3433aab403811152f20e397260.zip
Merge pull request #43 from Chocobo1/lint
Lint code
-rw-r--r--src/Makefile.am2
-rw-r--r--src/havege.c18
-rw-r--r--src/havegecmd.c4
-rw-r--r--src/havegecollect.c2
-rw-r--r--src/haveged.c9
-rw-r--r--src/havegetest.c16
-rw-r--r--src/havegetune.c2
7 files changed, 38 insertions, 15 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index d1d7d2c..c507ea4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -6,7 +6,7 @@ else
sbin_PROGRAMS = haveged
endif
-AM_CFLAGS=-Wall -I..
+AM_CFLAGS=-Wall -Wextra -Wpedantic -I..
####nolibtool_start##
##haveged_SOURCES = haveged.c havege.c havegetune.c havegecollect.c havegetest.c havegecmd.c \
diff --git a/src/havege.c b/src/havege.c
index 1b7a979..880e7fc 100644
--- a/src/havege.c
+++ b/src/havege.c
@@ -321,7 +321,7 @@ int havege_status_dump( /* RETURN: output length */
havege_status(hptr, &status);
switch(topic) {
case H_SD_TOPIC_BUILD:
- n += snprintf(buf, len, "ver: %s; arch: %s; vend: %s; build: (%s); collect: %dK",
+ n += snprintf(buf, len, "ver: %s; arch: %s; vend: %s; build: (%s); collect: %uK",
status.version,
hptr->arch,
status.vendor,
@@ -330,7 +330,7 @@ int havege_status_dump( /* RETURN: output length */
);
break;
case H_SD_TOPIC_TUNE:
- n += snprintf(buf, len, "cpu: (%s); data: %dK (%s); inst: %dK (%s); idx: %d/%d; sz: %d/%d",
+ n += snprintf(buf, len, "cpu: (%s); data: %uK (%s); inst: %uK (%s); idx: %u/%u; sz: %u/%u",
status.cpuSources,
status.d_cache,
status.d_cacheSources,
@@ -347,16 +347,16 @@ int havege_status_dump( /* RETURN: output length */
if (strlen(status.tot_tests)>0) {
n += snprintf(buf+n, len-n, "tot tests(%s): ", status.tot_tests);
if ((m = status.n_tests[ H_OLT_TOT_A_P] + status.n_tests[ H_OLT_TOT_A_F])>0)
- n += snprintf(buf+n, len-n, "A:%d/%d ", status.n_tests[ H_OLT_TOT_A_P], m);
+ n += snprintf(buf+n, len-n, "A:%u/%u ", status.n_tests[ H_OLT_TOT_A_P], m);
if ((m = status.n_tests[ H_OLT_TOT_B_P] + status.n_tests[ H_OLT_TOT_B_F])>0)
- n += snprintf(buf+n, len, "B:%d/%d ", status.n_tests[ H_OLT_TOT_B_P], m);
+ n += snprintf(buf+n, len, "B:%u/%u ", status.n_tests[ H_OLT_TOT_B_P], m);
}
if (strlen(status.prod_tests)>0) {
n += snprintf(buf+n, len-n, "continuous tests(%s): ", status.prod_tests);
if ((m = status.n_tests[ H_OLT_PROD_A_P] + status.n_tests[ H_OLT_PROD_A_F])>0)
- n += snprintf(buf+n, len-n, "A:%d/%d ", status.n_tests[ H_OLT_PROD_A_P], m);
+ n += snprintf(buf+n, len-n, "A:%u/%u ", status.n_tests[ H_OLT_PROD_A_P], m);
if ((m = status.n_tests[ H_OLT_PROD_B_P] + status.n_tests[ H_OLT_PROD_B_F])>0)
- n += snprintf(buf+n, len, "B:%d/%d ", status.n_tests[ H_OLT_PROD_B_P], m);
+ n += snprintf(buf+n, len, "B:%u/%u ", status.n_tests[ H_OLT_PROD_B_P], m);
}
if (n>0)
n += snprintf(buf+n, len-n, " last entropy estimate %g", status.last_test8);
@@ -374,7 +374,7 @@ int havege_status_dump( /* RETURN: output length */
break;
factor /= 1024.0;
}
- n = snprintf(buf, len, "fills: %d, generated: %.4g %c bytes",
+ n = snprintf(buf, len, "fills: %u, generated: %.4g %c bytes",
hptr->n_fills,
sz / factor,
units[i]
@@ -406,11 +406,11 @@ const char *havege_version(const char *version)
H_UINT p, p_interface, p_revision, p_patch;
#ifdef HAVEGE_LIB_VERSION
- sscanf(HAVEGE_LIB_VERSION, "%d:%d:%d", &l_interface, &l_revision, &l_age);
+ sscanf(HAVEGE_LIB_VERSION, "%u:%u:%u", &l_interface, &l_revision, &l_age);
#endif
(void)l_interface;(void)l_revision;(void)l_age;(void)p_patch; /* No check for now */
- p = sscanf(version, "%d.%d.%d", &p_interface, &p_revision, &p_patch);
+ p = sscanf(version, "%u.%u.%u", &p_interface, &p_revision, &p_patch);
if (p!=3 || p_interface != 1 || p_revision != 9)
return NULL;
}
diff --git a/src/havegecmd.c b/src/havegecmd.c
index b691c29..5eb9146 100644
--- a/src/havegecmd.c
+++ b/src/havegecmd.c
@@ -191,7 +191,7 @@ int getcmd( /* RETURN: success or error */
const char* opt;
} cmds[] = {
{ "root=", MAGIC_CHROOT, 1, NULL }, /* New root */
- {}
+ {0}
}, *cmd = cmds;
int ret = -1;
@@ -227,7 +227,7 @@ int socket_handler( /* RETURN: closed file descriptor */
char *const argv[], /* IN: arguments for the haveged process */
struct pparams *params) /* IN: input params */
{
- struct ucred cred = {};
+ struct ucred cred = {0};
unsigned char magic[2], *ptr;
char *enqry;
char *optarg = NULL;
diff --git a/src/havegecollect.c b/src/havegecollect.c
index 02831b8..c83e961 100644
--- a/src/havegecollect.c
+++ b/src/havegecollect.c
@@ -458,7 +458,7 @@ static void havege_ndinit( /* RETURN: None */
if (0 != (h_ptr->havege_opts & H_DEBUG_COMPILE)) {
h_ptr->print_msg("Address %u=%p\n", i, addr[i]);
}
- RESULT[i] = abs(addr[i] - addr[LOOP_CT]);
+ RESULT[i] = labs(addr[i] - addr[LOOP_CT]);
if (i > 0 && 0 != (h_ptr->havege_opts & H_DEBUG_LOOP)) {
h_ptr->print_msg("Loop %u: offset=%u, delta=%u\n", i,RESULT[i],RESULT[i-1]-RESULT[i]);
}
diff --git a/src/haveged.c b/src/haveged.c
index e382040..135dbcb 100644
--- a/src/haveged.c
+++ b/src/haveged.c
@@ -328,6 +328,7 @@ int main(int argc, char **argv)
case '?':
case 'h':
usage(0, nopts, long_options, cmds);
+ /* fallthrough */
case 'V':
printf(VERSION_TEXT, HAVEGE_PREP_VERSION);
exit(EXIT_SUCCESS);
@@ -408,7 +409,7 @@ int main(int argc, char **argv)
fprintf(stderr, "%s: please check if there is another instance of haveged running\n", params->daemon);
fprintf(stderr, "%s: disabling command mode for this instance\n", params->daemon);
} else {
- fprintf(stderr, "%s: can not initialize command socket: %m\n", params->daemon);
+ fprintf(stderr, "%s: can not initialize command socket: %s\n", params->daemon, strerror(errno));
}
}
}
@@ -530,7 +531,7 @@ static int get_poolsize( /* RETURN: number of bits */
fclose(poolsize_fh);
osrel_fh = fopen(params->os_rel, "rb");
if (osrel_fh) {
- if (fscanf(osrel_fh,"%d.%d", &major, &minor)<2)
+ if (fscanf(osrel_fh,"%u.%u", &major, &minor)<2)
major = minor = 0;
fclose(osrel_fh);
if (major==2 && minor==4) max_bits *= 8;
@@ -762,12 +763,16 @@ static int get_runsize( /* RETURN: the size */
switch(*suffix) {
case 't': case 'T':
p2 += 1;
+ /* fallthrough */
case 'g': case 'G':
p2 += 1;
+ /* fallthrough */
case 'm': case 'M':
p2 += 1;
+ /* fallthrough */
case 'k': case 'K':
p2 += 1;
+ /* fallthrough */
case 0:
break;
default:
diff --git a/src/havegetest.c b/src/havegetest.c
index 8b423fb..b1376e7 100644
--- a/src/havegetest.c
+++ b/src/havegetest.c
@@ -251,10 +251,12 @@ static H_UINT aisProcedureA( /* RETURN: bits used */
case TEST_INIT:
p->bytesUsed = 0;
p->procRetry = 0;
+ /* fallthrough */
case TEST_RETRY:
p->procState = TEST_INPUT;
p->testState = TEST_INIT;
p->testId = p->testRun = 0;
+ /* fallthrough */
case TEST_INPUT:
p->data = (H_UINT8 *)buffer;
p->range = sz * sizeof(H_UINT) <<3;
@@ -277,6 +279,7 @@ static H_UINT aisProcedureA( /* RETURN: bits used */
else if (p->testState == TEST_INPUT)
return 0;
}
+ /* fallthrough */
case TEST_EVAL:
p->procState = TEST_DONE;
for (r = i = 0;i<p->testRun;i++)
@@ -330,10 +333,12 @@ static H_UINT aisProcedureB( /* RETURN: bits used */
case TEST_INIT:
p->bitsUsed = 0;
p->procRetry = 0;
+ /* fallthrough */
case TEST_RETRY:
p->testId = p->testNbr = 0;
p->procState = TEST_INPUT;
p->testState = TEST_INIT;
+ /* fallthrough */
case TEST_INPUT:
p->noise = buffer;
p->range = sz * BITS_PER_H_UINT;
@@ -353,6 +358,7 @@ static H_UINT aisProcedureB( /* RETURN: bits used */
context->szCarry = ct;
if (p->testState == TEST_INPUT)
return 0;
+ /* fallthrough */
case TEST_EVAL:
p->procState = TEST_DONE;
for (i=r=0;i<p->testNbr;i++)
@@ -408,6 +414,7 @@ static H_UINT aisSeq( /* RETURN: last bit index */
p->full = 0;
p->testState = TEST_INPUT;
SAVE(0,0,0);
+ /* fallthrough */
case TEST_INPUT:
RESTORE(j, hilf, deadman);
offs %= p->range;
@@ -451,6 +458,7 @@ static H_UINT aisSeq( /* RETURN: last bit index */
p->bitsUsed += i;
if (p->testState == TEST_INPUT)
break;
+ /* fallthrough */
case TEST_EVAL:
if (tid==1) {
double q[2];
@@ -690,10 +698,12 @@ static H_UINT fips140( /* RETURN: updated bit offset */
case TEST_INIT:
p->testState = TEST_INPUT;
p->bridge = 0;
+ /* fallthrough */
case TEST_INPUT:
offs = copyBits(p, offs, FIPS_USED);
if (p->testState!=TEST_EVAL)
break;
+ /* fallthrough */
case TEST_EVAL:
maxRun = ones = runLength = 0;
memset(poker, 0, 16*sizeof(H_UINT));
@@ -765,10 +775,12 @@ static H_UINT test0( /* RETURN: updated bit offset */
case TEST_INIT:
p->testState = TEST_INPUT;
p->bridge = 0;
+ /* fallthrough */
case TEST_INPUT:
offs = copyBits(p, offs, TEST0_USED);
if (p->testState!=TEST_EVAL)
break;
+ /* fallthrough */
case TEST_EVAL:
qsort(p->aux, TEST0_LENGTH, 6, test0cmp);
for (i=6,j=0;i<TEST0_LENGTH && j==0;i+=6)
@@ -888,6 +900,7 @@ static H_UINT test6a( /* RETURN: bit offset */
case TEST_INIT:
j = p->counter[0] = 0;
p->testState = TEST_INPUT;
+ /* fallthrough */
case TEST_INPUT:
{
BITSTREAM_OPEN(p->noise,offs);
@@ -923,6 +936,7 @@ static H_UINT test6a( /* RETURN: bit offset */
break;
}
}
+ /* fallthrough */
case TEST_EVAL:
p->results[p->testNbr].finalValue = (double)(p->counter[0]) / (double) AIS_LENGTH;
r = tid << 8;
@@ -958,6 +972,7 @@ static H_UINT test8( /* RETURN: bit offset */
memset(p->lastpos, 0, 256*sizeof(H_UINT));
SAVE8(0,0,0,0.0);
p->testState = TEST_INPUT;
+ /* fallthrough */
case TEST_INPUT:
RESTORE8(k,j,hilf,TG);
r = p->range - offs;
@@ -998,6 +1013,7 @@ static H_UINT test8( /* RETURN: bit offset */
p->bitsUsed += i;
if (p->testState == TEST_INPUT)
break;
+ /* fallthrough */
case TEST_EVAL:
tps->lastCoron = p->results[p->testNbr].finalValue = TG/(double)K;
r = tid<<8;
diff --git a/src/havegetune.c b/src/havegetune.c
index 19d3965..4b2c229 100644
--- a/src/havegetune.c
+++ b/src/havegetune.c
@@ -516,10 +516,12 @@ static void cpuid_configAmd(
for(i=0;i<n;i++)
cfg_bitSet(&w->cpuMap, i);
cfg_cpuAdd(anchor, SRC_CPUID_AMD8, w);
+ /* fallthrough */
case 6:
cpuid(0x80000006,0,regs);
cfg_cacheAdd(anchor, SRC_CPUID_AMD6, -1, 2, 'U', (regs[ECX]>>16) & 0xffff);
cfg_cacheAdd(anchor, SRC_CPUID_AMD6, -1, 3, 'U', ((regs[EDX]>>18) & 0x3fff)<<9);
+ /* fallthrough */
case 5:
cpuid(0x80000005,0,regs);
cfg_cacheAdd(anchor, SRC_CPUID_AMD5, -1, 1, 'D', (regs[ECX]>>24) & 0xff);