update cdatapack utilities to check open success

Summary:
Update cdatapack_dump and cdatapack_get to check the return value from
`open_datapack()` to confirm if they actually successfully opened the file.

Previously these programs would segfault if invoked with a non-existent path.

Reviewed By: quark-zju

Differential Revision: D8131017

fbshipit-source-id: 90800de57430efd176b8e71fa84161f7b288e375
This commit is contained in:
Adam Simpkins 2018-05-24 11:27:59 -07:00 committed by Facebook Github Bot
parent a6fcceea31
commit 7233f0dfb1
3 changed files with 17 additions and 2 deletions

View File

@ -1,5 +1,12 @@
LDFLAGS=-llz4
LDFLAGS = -llz4 -lcrypto
CC = gcc
CFLAGS = -g -std=c99 -Wall -Werror -I.. -I../..
all: cdatapack_dump cdatapack_get
cdatapack_dump: cdatapack_dump.o cdatapack.o
.o.c:
cdatapack_get: cdatapack_get.o cdatapack.o
%.o: %.c cdatapack.h
$(CC) $(CFLAGS) -c -o $@ $<

View File

@ -43,6 +43,10 @@ int main(int argc, char *argv[]) {
data_path, strlen(data_path));
free(data_path);
free(idx_path);
if (handle->status != DATAPACK_HANDLE_OK) {
fprintf(stderr, "failed to open pack: %d\n", handle->status);
return 1;
}
const uint8_t *ptr = handle->data_mmap;
const uint8_t *end = ptr + handle->data_file_sz;

View File

@ -53,6 +53,10 @@ int main(int argc, char *argv[]) {
data_path, strlen(data_path));
free(data_path);
free(idx_path);
if (handle->status != DATAPACK_HANDLE_OK) {
fprintf(stderr, "failed to open pack: %d\n", handle->status);
return 1;
}
uint8_t binhash[NODE_SZ];