fixed lib soname.
example : simple_compression : size overflow check
diff --git a/NEWS b/NEWS
index b4a200a..f6f1ad9 100644
--- a/NEWS
+++ b/NEWS
@@ -5,7 +5,8 @@
cli : new : added zstdless and zstdgrep tools
cli : fixed : status displays total amount decoded, even for file consisting of multiple frames (like pzstd)
cli : fixed : zstdcat
-library : changed : only public ZSTD_ symbols are now exposed
+lib : changed : only public ZSTD_ symbols are now exposed
+lib : fixed : soname
API : changed : zbuff prototypes now generate deprecation warnings
API : changed : streaming decompression implicit reset on starting new frame
API : added experimental : dictID retrieval functions
diff --git a/examples/simple_compression.c b/examples/simple_compression.c
index 332ce72..deb0bbf 100644
--- a/examples/simple_compression.c
+++ b/examples/simple_compression.c
@@ -8,9 +8,9 @@
-#include <stdlib.h> // malloc, exit
-#include <stdio.h> // fprintf, perror
-#include <string.h> // strerror
+#include <stdlib.h> // malloc, free, exit
+#include <stdio.h> // fprintf, perror, fopen, etc.
+#include <string.h> // strlen, strcat, memset, strerror
#include <errno.h> // errno
#include <sys/stat.h> // stat
#include <zstd.h> // presumes zstd library is installed
@@ -45,13 +45,18 @@
static void* loadFile_orDie(const char* fileName, size_t* size)
{
- off_t const buffSize = fsize_orDie(fileName);
+ off_t const fileSize = fsize_orDie(fileName);
+ size_t const buffSize = (size_t)fileSize;
+ if ((off_t)buffSize < fileSize) { /* narrowcast overflow */
+ fprintf(stderr, "%s : filesize too large \n", fileName);
+ exit(4);
+ }
FILE* const inFile = fopen_orDie(fileName, "rb");
void* const buffer = malloc_orDie(buffSize);
size_t const readSize = fread(buffer, 1, buffSize, inFile);
if (readSize != (size_t)buffSize) {
fprintf(stderr, "fread: %s : %s \n", fileName, strerror(errno));
- exit(4);
+ exit(5);
}
fclose(inFile); /* can't fail, read only */
*size = buffSize;
@@ -65,11 +70,11 @@
size_t const wSize = fwrite(buff, 1, buffSize, oFile);
if (wSize != (size_t)buffSize) {
fprintf(stderr, "fwrite: %s : %s \n", fileName, strerror(errno));
- exit(5);
+ exit(6);
}
if (fclose(oFile)) {
perror(fileName);
- exit(6);
+ exit(7);
}
}
@@ -84,7 +89,7 @@
size_t const cSize = ZSTD_compress(cBuff, cBuffSize, fBuff, fSize, 1);
if (ZSTD_isError(cSize)) {
fprintf(stderr, "error compressing %s : %s \n", fname, ZSTD_getErrorName(cSize));
- exit(7);
+ exit(8);
}
saveFile_orDie(oname, cBuff, cSize);
diff --git a/lib/Makefile b/lib/Makefile
index 44c64b8..21a805d 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -47,9 +47,9 @@
SHARED_EXT = dylib
SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT)
SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT)
- SONAME_FLAGS = -install_name $(PREFIX)/lib/$@.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER)
+ SONAME_FLAGS = -install_name $(PREFIX)/lib/libzstd.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER)
else
- SONAME_FLAGS = -Wl,-soname=$@.$(SHARED_EXT).$(LIBVER_MAJOR)
+ SONAME_FLAGS = -Wl,-soname=libzstd.$(SHARED_EXT).$(LIBVER_MAJOR)
SHARED_EXT = so
SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR)
SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)