Eliminate a possbility to cause segfault

This commit is contained in:
topjohnwu 2017-12-25 03:01:33 +08:00
parent 022b18c8ce
commit 84ffdf0ed5
3 changed files with 4 additions and 5 deletions

View File

@ -29,7 +29,7 @@ struct vector *vec_dup(struct vector *v);
for (int _ = 0; v && _ < (v)->size; ++_, e = (v)->data[_])
#define vec_for_each_r(v, e) \
e = v ? (v)->data[(v)->size - 1] : NULL; \
e = (v && (v)->size > 0) ? (v)->data[(v)->size - 1] : NULL; \
for (int _ = ((int) (v)->size) - 1; v && _ >= 0; --_, e = (v)->data[_])
#define vec_cur(v) vec_entry(v)[_]

View File

@ -49,7 +49,7 @@ static void dtb_dump(const char *file) {
for (int i = 0; i < size; ++i) {
if (memcmp(dtb + i, DTB_MAGIC, 4) == 0) {
fdt = dtb + i;
fprintf(stderr, "Dumping dtb.%04d\n\n", dtb_num++);
fprintf(stderr, "Dumping dtb.%04d\n", dtb_num++);
print_subnode(fdt, 0, 0);
}
}
@ -61,7 +61,7 @@ static void dtb_dump(const char *file) {
static void dtb_patch(const char *file, int patch) {
size_t size ;
void *dtb, *fdt;
fprintf(stderr, "Loading dtbs from [%s]\n\n", file);
fprintf(stderr, "Loading dtbs from [%s]\n", file);
if (patch)
mmap_rw(file, &dtb, &size);
else
@ -84,7 +84,6 @@ static void dtb_patch(const char *file, int patch) {
}
}
}
fprintf(stderr, "\n");
munmap(dtb, size);
exit(!found);
}

View File

@ -57,9 +57,9 @@ void cpio_vec_insert(struct vector *v, cpio_entry *n) {
// Parse cpio file to a vector of cpio_entry
void parse_cpio(struct vector *v, const char *filename) {
fprintf(stderr, "Loading cpio: [%s]\n", filename);
int fd = open(filename, O_RDONLY);
if (fd < 0) return;
fprintf(stderr, "Loading cpio: [%s]\n", filename);
cpio_newc_header header;
cpio_entry *f;
while(xxread(fd, &header, 110) != -1) {