mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-06 19:19:16 +00:00
Issue #9, fixed a compiler warning and bug
The warning was that 'fd' could be used uninitialised in rhizome_store_file(), and it was true!
This commit is contained in:
parent
f527ae9425
commit
37d4b4fa3a
@ -856,6 +856,8 @@ int rhizome_store_file(rhizome_manifest *m,const unsigned char *key)
|
|||||||
if (!m->fileHashedP)
|
if (!m->fileHashedP)
|
||||||
return WHY("Cannot store bundle file until it has been hashed");
|
return WHY("Cannot store bundle file until it has been hashed");
|
||||||
|
|
||||||
|
int fd = -1;
|
||||||
|
|
||||||
/* See if the file is already stored, and if so, don't bother storing it again.
|
/* See if the file is already stored, and if so, don't bother storing it again.
|
||||||
Do this check BEFORE trying to open the associated file, because if the caller
|
Do this check BEFORE trying to open the associated file, because if the caller
|
||||||
has received a manifest and checked that it exists in the database, it may
|
has received a manifest and checked that it exists in the database, it may
|
||||||
@ -881,16 +883,16 @@ int rhizome_store_file(rhizome_manifest *m,const unsigned char *key)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fd=open(file,O_RDONLY);
|
fd = open(file, O_RDONLY);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
WHY_perror("open");
|
WHYF_perror("open(%s)", alloca_str_toprint(file));
|
||||||
WHY("Could not open associated file");
|
WHY("Could not open associated file");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct stat stat;
|
struct stat stat;
|
||||||
if (fstat(fd, &stat)) {
|
if (fstat(fd, &stat)) {
|
||||||
WHY_perror("fstat");
|
WHYF_perror("fstat(%d)", fd);
|
||||||
WHY("Could not stat() associated file");
|
WHY("Could not stat() associated file");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -908,7 +910,7 @@ int rhizome_store_file(rhizome_manifest *m,const unsigned char *key)
|
|||||||
|
|
||||||
unsigned char *addr = mmap(NULL, m->fileLength, PROT_READ, MAP_SHARED, fd, 0);
|
unsigned char *addr = mmap(NULL, m->fileLength, PROT_READ, MAP_SHARED, fd, 0);
|
||||||
if (addr==MAP_FAILED) {
|
if (addr==MAP_FAILED) {
|
||||||
WHY_perror("mmap");
|
WHYF_perror("mmap(NULL, %lld, PROT_READ, MAP_SHARED, %d, 0)", (long long) m->fileLength, fd);
|
||||||
WHY("mmap() of associated file failed.");
|
WHY("mmap() of associated file failed.");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user