corrections from linux gcc v11 compilation
authorLaurent Mazet <laurent.mazet@thalesgroup.com>
Mon, 12 Dec 2022 11:21:09 +0000 (12:21 +0100)
committerLaurent Mazet <laurent.mazet@thalesgroup.com>
Mon, 12 Dec 2022 11:21:09 +0000 (12:21 +0100)
compress.c
fprintf.c

index 713fc5b0b94b415e6cfaa74db3a918da74d370e1..d27f8e5740982070b6383f5cc10cbef86ad52fd5 100644 (file)
 #define COMPRESS 1
 #define DECOMPRESS 2
 
+#ifndef O_RAW
+#define O_RAW 0
+#endif /* O_RAW */
+
 /* macros */
 
 /* gobal variables */
@@ -356,7 +360,7 @@ int write_compress (char *output, char *input, code_t *codes, byte_t *header)
     char bits[(NB_BYTES - 1) + 8 + 1] = {0};
     int fin, fout;
     int length = 0;
-    int i, j, nbread;
+    int i, j, nbread, nbwrite;
     byte_t *pt;
 
     VERBOSE (DEBUG, PRINTOUT ("start writting compressed file\n"));
@@ -381,7 +385,14 @@ int write_compress (char *output, char *input, code_t *codes, byte_t *header)
     /* write header */
     length = (header[3] << 8) + header[4];
     VERBOSE (DEBUG, PRINTOUT ("lengh: %d\n", length));
-    write (fout, header, length + 6);
+    nbwrite = write (fout, header, length + 6);
+    if (nbwrite != length + 6) {
+        VERBOSE (ERROR, PRINTERR ("can't write %d bytes in file '%s'\n", length + 6 - nbwrite, output));
+           close (fout);
+           close (fin);
+        return 1;
+    }
+
 
     /* write file */
     pt = bufout;
@@ -398,7 +409,13 @@ int write_compress (char *output, char *input, code_t *codes, byte_t *header)
                 }
                 codcpy (bits, sizeof (code_t), bits + 8);
                 if (pt - bufout == BUFFER_SIZE - 1) {
-                    write (fout, bufout, BUFFER_SIZE);
+                    nbwrite = write (fout, bufout, BUFFER_SIZE);
+                    if (nbwrite != BUFFER_SIZE) {
+                        VERBOSE (ERROR, PRINTERR ("can't write %d bytes in file '%s'\n", BUFFER_SIZE - nbwrite, output));
+                           close (fout);
+                           close (fin);
+                        return 1;
+                    }
                     pt = bufout;
                 } else {
                     pt++;
@@ -421,7 +438,13 @@ int write_compress (char *output, char *input, code_t *codes, byte_t *header)
     }
     if (pt != bufout) {
         VERBOSE (DEBUG, PRINTOUT ("last partial buffer written: %u\n", pt - bufout));
-        write (fout, bufout, pt - bufout);
+        nbwrite = write (fout, bufout, pt - bufout);
+        if (nbwrite != pt - bufout) {
+            VERBOSE (ERROR, PRINTERR ("can't write %d bytes in file '%s'\n", pt - bufout - nbwrite, output));
+               close (fout);
+               close (fin);
+            return 1;
+        }
     }
     
     /* closing */
@@ -539,7 +562,7 @@ int write_decompress (char *output, char *input, code_t *codes)
     byte_t bufhea[MAX(NB_BYTES * (NB_BYTES - 1) / 2 / 8 + NB_BYTES + 6, BUFFER_SIZE)] = {0};
     char bits[(NB_BYTES - 1) + 1] = {0};
     int fin, fout;
-    int i, j, k, nb, size, rem;
+    int i, j, k, nb, size, nbwrite, rem;
     int is_found;
     int l = 0;
     byte_t *pt;
@@ -577,7 +600,7 @@ int write_decompress (char *output, char *input, code_t *codes)
     if (fout == -1) {
         VERBOSE (ERROR, PRINTERR ("can't open file '%s' for writing\n", output));
         close (fin);
-       return 2;
+           return 1;
     }
     VERBOSE (INFO, PRINTOUT ("file '%s' opened\n", output));
 
@@ -602,7 +625,13 @@ int write_decompress (char *output, char *input, code_t *codes)
                         bits[0] = 0;
                         if (pt - bufout == BUFFER_SIZE - 1) {
                             VERBOSE (DEBUG, PRINTOUT ("nb buffer out: %u\n", (pt - bufout)));
-                            write (fout, bufout, BUFFER_SIZE);
+                            nbwrite = write (fout, bufout, BUFFER_SIZE);
+                            if (nbwrite != BUFFER_SIZE) {
+                                VERBOSE (ERROR, PRINTERR ("can't write %d bytes in file '%s'\n'", BUFFER_SIZE - nbwrite, output));
+                                close (fout);
+                                close (fin);
+                                return 1;
+                            }
                             pt = bufout;
                         } else {
                             pt++;
@@ -618,7 +647,13 @@ int write_decompress (char *output, char *input, code_t *codes)
     }
     if (pt != bufout) {
         VERBOSE (DEBUG, PRINTOUT ("nb buffer out: %u\n", (pt - bufout)));
-        write (fout, bufout, pt - bufout);
+        nbwrite = write (fout, bufout, pt - bufout);
+        if (nbwrite != pt - bufout) {
+            VERBOSE (ERROR, PRINTERR ("can't write %d bytes in file '%s'\n'", pt - bufout - nbwrite, output));
+            close (fout);
+            close (fin);
+            return 1;
+        }
     }
 
     /* close files */
index f74189c369b906be442261fbcfbe20ecc523614f..ff4f0353d1f947cd79e4bbba8690d0254efb3976 100644 (file)
--- a/fprintf.c
+++ b/fprintf.c
@@ -12,6 +12,7 @@
 */
 
 #include <stdarg.h>
+#include <stdint.h>
 #include <unistd.h>
 
 #include "fprintf.h"
@@ -19,7 +20,7 @@
 int _fdout = STDOUT_FILENO;
 int _fderr = STDERR_FILENO;
 
-inline unsigned int nextpow (unsigned int x, int base) {
+unsigned int nextpow (unsigned int x, int base) {
     unsigned int n = 0;
     while (x) {
         n++;
@@ -94,13 +95,14 @@ int fdprintf (int fd, const char *fmt, ...)
             case 'x': /* integer hexa */
                 if (!p) {
                     u = va_arg (ap, unsigned int);
-                    p = (void *)u;
                     if (sz == 0) {
                         sz = nextpow (u, 16);
                     }
+                } else {
+                    u = (uintptr_t)p;
                 }
                 for (i = sz, t = 1; i > 0; i--) {
-                    char x = (char)(((uintptr_t)p >> (i * 4 - 4)) & 0xf);
+                    char x = (char)((u >> (i * 4 - 4)) & 0xf);
                     if ((t == 1) && (x == 0)) {
                         *str++ = w;
                     } else {
@@ -124,8 +126,7 @@ int fdprintf (int fd, const char *fmt, ...)
     /* output string */
     int n = str - buffer;
     if (n < (int)sizeof (buffer) - 1) {
-        write (fd, buffer, n);
-        return n;
+        return write (fd, buffer, n);
     }
     return 0;
 }