From: Sergey Matveev <stargrave@stargrave.org>
Date: Fri, 17 Dec 2021 14:43:15 +0000 (+0300)
Subject: uint8_t -> char
X-Git-Tag: v0.1.0~38
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=8bc77b4488055c6892b991407cac6dd3a4ce99a5;p=tofuproxy.git

uint8_t -> char

Because only character types are safe for strict aliasing.
POSIX requires them to be 8-bit and two's complement.
---

diff --git a/cmd/zstd/default.do b/cmd/zstd/default.do
index 387fbb5..c329637 100644
--- a/cmd/zstd/default.do
+++ b/cmd/zstd/default.do
@@ -2,4 +2,4 @@ src=$1.c
 redo-ifchange $src conf/zstd.cflags.rc conf/zstd.libs.rc
 read ZSTD_CFLAGS < conf/zstd.cflags.rc
 read ZSTD_LIBS < conf/zstd.libs.rc
-${CC:-cc} $CFLAGS $ZSTD_CFLAGS -o $3 $src $ZSTD_LIBS
+${CC:-cc} -fstrict-aliasing $CFLAGS $ZSTD_CFLAGS -o $3 $src $ZSTD_LIBS
diff --git a/cmd/zstd/enzstd.c b/cmd/zstd/enzstd.c
index c393f77..1c66962 100644
--- a/cmd/zstd/enzstd.c
+++ b/cmd/zstd/enzstd.c
@@ -50,13 +50,13 @@ main(int argc, char **argv)
 
     int rc         = EXIT_FAILURE;
     size_t srcSize = 8;
-    uint8_t *src   = malloc(srcSize);
+    char *src      = malloc(srcSize);
     if (src == NULL) {
         fprintf(stderr, "can not allocate memory: %zu\n", srcSize);
         goto Exit;
     };
     size_t dstSize     = 0;
-    uint8_t *dst       = NULL;
+    char *dst          = NULL;
     size_t srcWantSize = 0;
     size_t dstWantSize = 0;
     size_t n           = 0;
diff --git a/cmd/zstd/unzstd.c b/cmd/zstd/unzstd.c
index caddee5..1e0c1cd 100644
--- a/cmd/zstd/unzstd.c
+++ b/cmd/zstd/unzstd.c
@@ -51,8 +51,8 @@ main(int argc, char **argv)
         return 1;
     };
     int rc                 = EXIT_FAILURE;
-    uint8_t *bufIn         = NULL;
-    uint8_t *bufOut        = NULL;
+    char *bufIn            = NULL;
+    char *bufOut           = NULL;
     const size_t bufInSize = ZSTD_DStreamInSize();
     bufIn                  = malloc(bufInSize);
     if (bufIn == NULL) {
@@ -92,7 +92,7 @@ ReadAgain:
         if (n >= 8 && le32dec(bufIn) == 0x184D2A5D) {
             // dictionary frame
             size_t dictSize = (size_t)le32dec(bufIn + 4);
-            uint8_t *dict   = malloc(dictSize);
+            char *dict      = malloc(dictSize);
             if (dict == NULL) {
                 fprintf(stderr, "insufficient memory for dictionary: %zu\n", dictSize);
                 goto Exit;
@@ -134,7 +134,7 @@ ReadAgain:
                     free(dict);
                     goto Exit;
                 };
-                uint8_t *buf = malloc(bufSize);
+                char *buf = malloc(bufSize);
                 if (buf == NULL) {
                     fprintf(
                         stderr, "insufficient memory for dictionary: %llu\n", bufSize);