@@ -137,6 +137,10 @@ static uint16_t be16(uint16_t x) {
137137 return x ;
138138}
139139
140+ static int16_t sbe16 (int16_t x ) {
141+ return (int16_t )be16 ((uint16_t )x );
142+ }
143+
140144static uint32_t be32 (uint32_t x ) {
141145 char * b = (char * )& x ;
142146
@@ -153,6 +157,10 @@ static uint32_t be32(uint32_t x) {
153157 return x ;
154158}
155159
160+ static int32_t sbe32 (int32_t x ) {
161+ return (int32_t )be32 ((uint32_t )x );
162+ }
163+
156164static uint64_t be64 (uint64_t x ) {
157165 char * b = (char * )& x ;
158166
@@ -179,6 +187,10 @@ static uint64_t be64(uint64_t x) {
179187 return x ;
180188}
181189
190+ static int64_t sbe64 (int64_t x ) {
191+ return (int64_t )be64 ((uint64_t )x );
192+ }
193+
182194#ifndef CMP_NO_FLOAT
183195static float decode_befloat (const char * b ) {
184196 float f = 0. ;
@@ -583,7 +595,7 @@ static bool read_obj_data(cmp_ctx_t *ctx, uint8_t type_marker,
583595 obj -> as .u8 = type_marker ;
584596 return true;
585597 case CMP_TYPE_NEGATIVE_FIXNUM :
586- obj -> as .s8 = type_marker ;
598+ obj -> as .s8 = ( int8_t ) type_marker ;
587599 return true;
588600 case CMP_TYPE_NIL :
589601 obj -> as .u8 = 0 ;
@@ -639,21 +651,21 @@ static bool read_obj_data(cmp_ctx_t *ctx, uint8_t type_marker,
639651 ctx -> error = DATA_READING_ERROR ;
640652 return false;
641653 }
642- obj -> as .s16 = be16 (obj -> as .s16 );
654+ obj -> as .s16 = sbe16 (obj -> as .s16 );
643655 return true;
644656 case CMP_TYPE_SINT32 :
645657 if (!ctx -> read (ctx , & obj -> as .s32 , sizeof (int32_t ))) {
646658 ctx -> error = DATA_READING_ERROR ;
647659 return false;
648660 }
649- obj -> as .s32 = be32 (obj -> as .s32 );
661+ obj -> as .s32 = sbe32 (obj -> as .s32 );
650662 return true;
651663 case CMP_TYPE_SINT64 :
652664 if (!ctx -> read (ctx , & obj -> as .s64 , sizeof (int64_t ))) {
653665 ctx -> error = DATA_READING_ERROR ;
654666 return false;
655667 }
656- obj -> as .s64 = be64 (obj -> as .s64 );
668+ obj -> as .s64 = sbe64 (obj -> as .s64 );
657669 return true;
658670 case CMP_TYPE_FLOAT :
659671 {
@@ -809,15 +821,15 @@ bool cmp_write_pfix(cmp_ctx_t *ctx, uint8_t c) {
809821
810822bool cmp_write_nfix (cmp_ctx_t * ctx , int8_t c ) {
811823 if (c >= -32 && c <= -1 )
812- return write_fixed_value (ctx , c );
824+ return write_fixed_value (ctx , ( uint8_t ) c );
813825
814826 ctx -> error = INPUT_VALUE_TOO_LARGE_ERROR ;
815827 return false;
816828}
817829
818830bool cmp_write_sfix (cmp_ctx_t * ctx , int8_t c ) {
819831 if (c >= 0 )
820- return cmp_write_pfix (ctx , c );
832+ return cmp_write_pfix (ctx , ( uint8_t ) c );
821833 if (c >= -32 && c <= -1 )
822834 return cmp_write_nfix (ctx , c );
823835
@@ -836,7 +848,7 @@ bool cmp_write_s16(cmp_ctx_t *ctx, int16_t s) {
836848 if (!write_type_marker (ctx , S16_MARKER ))
837849 return false;
838850
839- s = be16 (s );
851+ s = sbe16 (s );
840852
841853 return ctx -> write (ctx , & s , sizeof (int16_t ));
842854}
@@ -845,7 +857,7 @@ bool cmp_write_s32(cmp_ctx_t *ctx, int32_t i) {
845857 if (!write_type_marker (ctx , S32_MARKER ))
846858 return false;
847859
848- i = be32 (i );
860+ i = sbe32 (i );
849861
850862 return ctx -> write (ctx , & i , sizeof (int32_t ));
851863}
@@ -854,14 +866,14 @@ bool cmp_write_s64(cmp_ctx_t *ctx, int64_t l) {
854866 if (!write_type_marker (ctx , S64_MARKER ))
855867 return false;
856868
857- l = be64 (l );
869+ l = sbe64 (l );
858870
859871 return ctx -> write (ctx , & l , sizeof (int64_t ));
860872}
861873
862874bool cmp_write_integer (cmp_ctx_t * ctx , int64_t d ) {
863875 if (d >= 0 )
864- return cmp_write_uinteger (ctx , d );
876+ return cmp_write_uinteger (ctx , ( uint64_t ) d );
865877 if (d >= -32 )
866878 return cmp_write_nfix (ctx , (int8_t )d );
867879 if (d >= -128 )
@@ -1861,7 +1873,7 @@ bool cmp_read_char(cmp_ctx_t *ctx, int8_t *c) {
18611873 return true;
18621874 case CMP_TYPE_UINT8 :
18631875 if (obj .as .u8 <= 127 ) {
1864- * c = obj .as .u8 ;
1876+ * c = ( int8_t ) obj .as .u8 ;
18651877 return true;
18661878 }
18671879 break ;
@@ -1893,7 +1905,7 @@ bool cmp_read_short(cmp_ctx_t *ctx, int16_t *s) {
18931905 return true;
18941906 case CMP_TYPE_UINT16 :
18951907 if (obj .as .u16 <= 32767 ) {
1896- * s = obj .as .u16 ;
1908+ * s = ( int16_t ) obj .as .u16 ;
18971909 return true;
18981910 }
18991911 break ;
@@ -1931,7 +1943,7 @@ bool cmp_read_int(cmp_ctx_t *ctx, int32_t *i) {
19311943 return true;
19321944 case CMP_TYPE_UINT32 :
19331945 if (obj .as .u32 <= 2147483647 ) {
1934- * i = obj .as .u32 ;
1946+ * i = ( int32_t ) obj .as .u32 ;
19351947 return true;
19361948 }
19371949 break ;
@@ -1975,7 +1987,7 @@ bool cmp_read_long(cmp_ctx_t *ctx, int64_t *d) {
19751987 return true;
19761988 case CMP_TYPE_UINT64 :
19771989 if (obj .as .u64 <= 9223372036854775807 ) {
1978- * d = obj .as .u64 ;
1990+ * d = ( int64_t ) obj .as .u64 ;
19791991 return true;
19801992 }
19811993 break ;
@@ -2069,7 +2081,7 @@ bool cmp_read_uchar(cmp_ctx_t *ctx, uint8_t *c) {
20692081 case CMP_TYPE_NEGATIVE_FIXNUM :
20702082 case CMP_TYPE_SINT8 :
20712083 if (obj .as .s8 >= 0 ) {
2072- * c = obj .as .s8 ;
2084+ * c = ( uint8_t ) obj .as .s8 ;
20732085 return true;
20742086 }
20752087 break ;
@@ -2098,13 +2110,13 @@ bool cmp_read_ushort(cmp_ctx_t *ctx, uint16_t *s) {
20982110 case CMP_TYPE_NEGATIVE_FIXNUM :
20992111 case CMP_TYPE_SINT8 :
21002112 if (obj .as .s8 >= 0 ) {
2101- * s = obj .as .s8 ;
2113+ * s = ( uint8_t ) obj .as .s8 ;
21022114 return true;
21032115 }
21042116 break ;
21052117 case CMP_TYPE_SINT16 :
21062118 if (obj .as .s16 >= 0 ) {
2107- * s = obj .as .s16 ;
2119+ * s = ( uint16_t ) obj .as .s16 ;
21082120 return true;
21092121 }
21102122 break ;
@@ -2136,19 +2148,19 @@ bool cmp_read_uint(cmp_ctx_t *ctx, uint32_t *i) {
21362148 case CMP_TYPE_NEGATIVE_FIXNUM :
21372149 case CMP_TYPE_SINT8 :
21382150 if (obj .as .s8 >= 0 ) {
2139- * i = obj .as .s8 ;
2151+ * i = ( uint8_t ) obj .as .s8 ;
21402152 return true;
21412153 }
21422154 break ;
21432155 case CMP_TYPE_SINT16 :
21442156 if (obj .as .s16 >= 0 ) {
2145- * i = obj .as .s16 ;
2157+ * i = ( uint16_t ) obj .as .s16 ;
21462158 return true;
21472159 }
21482160 break ;
21492161 case CMP_TYPE_SINT32 :
21502162 if (obj .as .s32 >= 0 ) {
2151- * i = obj .as .s32 ;
2163+ * i = ( uint32_t ) obj .as .s32 ;
21522164 return true;
21532165 }
21542166 break ;
@@ -2183,25 +2195,25 @@ bool cmp_read_ulong(cmp_ctx_t *ctx, uint64_t *u) {
21832195 case CMP_TYPE_NEGATIVE_FIXNUM :
21842196 case CMP_TYPE_SINT8 :
21852197 if (obj .as .s8 >= 0 ) {
2186- * u = obj .as .s8 ;
2198+ * u = ( uint8_t ) obj .as .s8 ;
21872199 return true;
21882200 }
21892201 break ;
21902202 case CMP_TYPE_SINT16 :
21912203 if (obj .as .s16 >= 0 ) {
2192- * u = obj .as .s16 ;
2204+ * u = ( uint16_t ) obj .as .s16 ;
21932205 return true;
21942206 }
21952207 break ;
21962208 case CMP_TYPE_SINT32 :
21972209 if (obj .as .s32 >= 0 ) {
2198- * u = obj .as .s32 ;
2210+ * u = ( uint32_t ) obj .as .s32 ;
21992211 return true;
22002212 }
22012213 break ;
22022214 case CMP_TYPE_SINT64 :
22032215 if (obj .as .s64 >= 0 ) {
2204- * u = obj .as .s64 ;
2216+ * u = ( uint64_t ) obj .as .s64 ;
22052217 return true;
22062218 }
22072219 break ;
@@ -3243,7 +3255,7 @@ bool cmp_object_as_short(const cmp_object_t *obj, int16_t *s) {
32433255 return true;
32443256 case CMP_TYPE_UINT16 :
32453257 if (obj -> as .u16 <= 32767 ) {
3246- * s = obj -> as .u16 ;
3258+ * s = ( int16_t ) obj -> as .u16 ;
32473259 return true;
32483260 }
32493261 else {
@@ -3275,7 +3287,7 @@ bool cmp_object_as_int(const cmp_object_t *obj, int32_t *i) {
32753287 return true;
32763288 case CMP_TYPE_UINT32 :
32773289 if (obj -> as .u32 <= 2147483647 ) {
3278- * i = obj -> as .u32 ;
3290+ * i = ( int32_t ) obj -> as .u32 ;
32793291 return true;
32803292 }
32813293 else {
@@ -3313,7 +3325,7 @@ bool cmp_object_as_long(const cmp_object_t *obj, int64_t *d) {
33133325 return true;
33143326 case CMP_TYPE_UINT64 :
33153327 if (obj -> as .u64 <= 9223372036854775807 ) {
3316- * d = obj -> as .u64 ;
3328+ * d = ( int64_t ) obj -> as .u64 ;
33173329 return true;
33183330 }
33193331 else {
0 commit comments