Skip to content

Commit 9ba4791

Browse files
alradmsftthiagomacieira
authored andcommitted
Supress data loss warnings in VS2015
Where safe, use explicit casts to supress data loss warnings in VS2015 compiler. This fixes #45. Signed-off-by: Alex Radutskiy ([email protected]) Signed-off-by: Thiago Macieira <[email protected]>
1 parent ad09b6a commit 9ba4791

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/cborencoder.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ static inline CborError encode_number_no_update(CborEncoder *encoder, uint64_t u
290290
if (ui < Value8Bit) {
291291
*bufstart += shiftedMajorType;
292292
} else {
293-
unsigned more = 0;
293+
uint8_t more = 0;
294294
if (ui > 0xffU)
295295
++more;
296296
if (ui > 0xffffU)

src/cborparser.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static CborError extract_length(const CborParser *parser, const uint8_t **ptr, s
155155
return err;
156156
}
157157

158-
*len = v;
158+
*len = (size_t)v;
159159
if (v != *len)
160160
return CborErrorDataTooLarge;
161161
return CborNoError;
@@ -799,13 +799,13 @@ CborError cbor_value_get_int_checked(const CborValue *value, int *result)
799799
if (unlikely(v > (unsigned) -(INT_MIN + 1)))
800800
return CborErrorDataTooLarge;
801801

802-
*result = v;
802+
*result = (int)v;
803803
*result = -*result - 1;
804804
} else {
805805
if (unlikely(v > (uint64_t)INT_MAX))
806806
return CborErrorDataTooLarge;
807807

808-
*result = v;
808+
*result = (int)v;
809809
}
810810
return CborNoError;
811811

src/compilersupport_p.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ static inline unsigned short encode_half(double val)
210210
/* underflow, make zero */
211211
return 0;
212212
}
213-
return sign | ((exp + 15) << 10) | mant;
213+
214+
/* safe cast here as bit operations above guarantee not to overflow */
215+
return (unsigned short)(sign | ((exp + 15) << 10) | mant);
214216
#endif
215217
}
216218

0 commit comments

Comments
 (0)