]> pd.if.org Git - pdclib/blobdiff - opt/basecodecs/_PDCLIB_latin1.c
Pointer typedef resulted in non-const structure where const was intended.
[pdclib] / opt / basecodecs / _PDCLIB_latin1.c
index 73844f417b6aa32587cf5f1e03346d6330d0e0e1..5961a443d7e46319bf812980d7cad4eecb5e4246 100644 (file)
@@ -7,21 +7,28 @@
 #include <stdbool.h>
 #ifndef REGTEST
 #include <uchar.h>
+#include <_PDCLIB_encoding.h>
+
+static bool latin1_mbsinit( const mbstate_t *ps )
+{ return 1; }
 
 static bool latin1toc32(
-    char32_t       **restrict   p_outbuf,
-    size_t          *restrict   p_outsz,
-    const char     **restrict   p_inbuf,
-    size_t          *restrict   p_insz,
-    mbstate_t       *restrict   p_ps
+    char32_t       *restrict *restrict   p_outbuf,
+    size_t                   *restrict   p_outsz,
+    const char     *restrict *restrict   p_inbuf,
+    size_t                   *restrict   p_insz,
+    mbstate_t                *restrict   p_ps
 )
 {
     while(*p_outsz && *p_insz) {
         unsigned char c = **p_inbuf;
-        **p_outbuf = c;
+
+        if(p_outbuf) {
+            **p_outbuf = c;
+            (*p_outbuf)++; 
+        }
 
         (*p_inbuf)++;
-        (*p_outbuf)++; 
         (*p_insz)--; 
         (*p_outsz)--;
     }
@@ -29,26 +36,37 @@ static bool latin1toc32(
 }
 
 static bool c32tolatin1(
-    char           **restrict  p_outbuf,
-    size_t          *restrict  p_outsz,
-    const char32_t **restrict  p_inbuf,
-    size_t          *restrict  p_insz,
-    mbstate_t       *restrict  p_ps
+    char           *restrict *restrict  p_outbuf,
+    size_t                   *restrict  p_outsz,
+    const char32_t *restrict *restrict  p_inbuf,
+    size_t                   *restrict  p_insz,
+    mbstate_t                *restrict  p_ps
 )
 {
     while(*p_outsz && *p_insz) {
         char32_t c = **p_inbuf;
         if(c > 255)
             return false;
-        **p_outbuf = c;
+
+        if(p_outbuf) {
+            **p_outbuf = c;
+            (*p_outbuf)++;
+        }
 
         (*p_inbuf)++;
-        (*p_outbuf)++; 
         (*p_insz)--; 
         (*p_outsz)--;        
     }
     return true;
 }
+
+const struct _PDCLIB_charcodec_t _PDCLIB_latin1_codec = {
+    .__mbsinit   = latin1_mbsinit,
+    .__mbstoc32s = latin1toc32,
+    .__c32stombs = c32tolatin1,
+    .__mb_max    = 1,
+};
+
 #endif
 
 #ifdef TEST