Skip to content

Commit 542b0cd

Browse files
committed
Reduce compiler warnungs: initialize variables, add casts to avoid overflows
Signed-off-by: Lars H. Rohwedder <RokerHRO@users.noreply.github.com>
1 parent 839fd7f commit 542b0cd

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

cliserv.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,9 @@ uint64_t ntohll(uint64_t a) {
117117
* @return 0 on completion, or -1 on failure
118118
**/
119119
int readit(int f, void *buf, size_t len) {
120-
ssize_t res;
121120
while (len > 0) {
122121
DEBUG("*");
123-
res = read(f, buf, len);
122+
ssize_t res = read(f, buf, len);
124123
if (res > 0) {
125124
len -= res;
126125
buf += res;

nbdsrv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ bool address_matches(const char* mask, const struct sockaddr* addr, GError** err
3333
struct addrinfo *res, *aitmp, hints;
3434
char *masksep;
3535
char privmask[strlen(mask)+1];
36-
int masklen;
37-
int addrlen = addr->sa_family == AF_INET ? 4 : 16;
36+
long masklen = 0;
37+
long addrlen = addr->sa_family == AF_INET ? 4 : 16;
3838
#define IPV4_MAP_PREFIX 12
3939
uint8_t ipv4_mapped[IPV4_MAP_PREFIX+4] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4040
255, 255, 0, 0, 0, 0};

tests/code/dup.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ int stringcmp(const char* a, const char* b) {
1717
}
1818

1919
int main(void) {
20-
SERVER *srvd;
2120
SERVER srvs = {
2221
.exportname = "foo",
2322
.expected_size = 0,
@@ -34,7 +33,7 @@ int main(void) {
3433
.cowdir = "/tmp",
3534
};
3635

37-
srvd = dup_serve(&srvs);
36+
SERVER *srvd = dup_serve(&srvs);
3837

3938
count_assert(&srvs != srvd);
4039
count_assert(stringcmp(srvs.exportname, srvd->exportname) == 0);

treefiles.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ void construct_path(char* name, int lenmax, off_t size, off_t pos, off_t* ppos)
1818
if (lenmax<10)
1919
err("Char buffer overflow. This is likely a bug.");
2020

21-
if (size<TREEDIRSIZE*TREEPAGESIZE) {
21+
if (size<(off_t)TREEDIRSIZE*TREEPAGESIZE) {
2222
// we are done, add filename
2323
snprintf(name,lenmax,"/FILE%04" PRIX64,(pos/TREEPAGESIZE) % TREEDIRSIZE);
24-
*ppos = pos / (TREEPAGESIZE*TREEDIRSIZE);
24+
*ppos = pos / ((off_t)TREEPAGESIZE*TREEDIRSIZE);
2525
} else {
2626
construct_path(name+9,lenmax-9,size/TREEDIRSIZE,pos,ppos);
2727
char buffer[10];

0 commit comments

Comments
 (0)