aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLev Walkin <vlm@lionet.info>2017-09-17 22:16:02 -0700
committerLev Walkin <vlm@lionet.info>2017-09-17 22:16:02 -0700
commit642b92f3feac17656d3f67c6da16c882011ca722 (patch)
tree0e93eb36ee5a2a7f471ae58e77bf5d508cccd0a7
parente0236da7cd1d9042c65d7064ef7fa8e7c152e7a3 (diff)
get rid of undefined behavior sanitizer warning
-rw-r--r--skeletons/INTEGER.c44
-rw-r--r--skeletons/asn_system.h8
2 files changed, 36 insertions, 16 deletions
diff --git a/skeletons/INTEGER.c b/skeletons/INTEGER.c
index 4dfb1f83..66a96f42 100644
--- a/skeletons/INTEGER.c
+++ b/skeletons/INTEGER.c
@@ -783,11 +783,34 @@ INTEGER_encode_uper(asn_TYPE_descriptor_t *td,
#endif /* ASN_DISABLE_PER_SUPPORT */
+
+/*
+ * This function is only to get rid of Undefined Behavior Sanitizer warning.
+ */
+static intmax_t CLANG_NO_SANITIZE("shift-base")
+asn__safe_integer_convert_helper(const uint8_t *b, const uint8_t *end) {
+ intmax_t value;
+
+ /* Perform the sign initialization */
+ /* Actually value = -(*b >> 7); gains nothing, yet unreadable! */
+ if((*b >> 7)) {
+ value = -1;
+ } else {
+ value = 0;
+ }
+
+ /* Conversion engine */
+ for(; b < end; b++) {
+ value = (value << 8) | *b;
+ }
+
+ return value;
+}
+
int
asn_INTEGER2imax(const INTEGER_t *iptr, intmax_t *lptr) {
uint8_t *b, *end;
size_t size;
- intmax_t value;
/* Sanity checking */
if(!iptr || !iptr->buf || !lptr) {
@@ -800,11 +823,11 @@ asn_INTEGER2imax(const INTEGER_t *iptr, intmax_t *lptr) {
size = iptr->size;
end = b + size; /* Where to stop */
- if(size > sizeof(value)) {
+ if(size > sizeof(intmax_t)) {
uint8_t *end1 = end - 1;
/*
* Slightly more advanced processing,
- * able to process INTEGERs with >sizeof(value) bytes
+ * able to process INTEGERs with >sizeof(intmax_t) bytes
* when the actual value is small, e.g. for intmax_t == int32_t
* (0x0000000000abcdef INTEGER would yield a fine 0x00abcdef int32_t)
*/
@@ -818,8 +841,8 @@ asn_INTEGER2imax(const INTEGER_t *iptr, intmax_t *lptr) {
}
size = end - b;
- if(size > sizeof(value)) {
- /* Still cannot fit the sizeof(value) */
+ if(size > sizeof(intmax_t)) {
+ /* Still cannot fit the sizeof(intmax_t) */
errno = ERANGE;
return -1;
}
@@ -831,16 +854,7 @@ asn_INTEGER2imax(const INTEGER_t *iptr, intmax_t *lptr) {
return 0;
}
- /* Perform the sign initialization */
- /* Actually value = -(*b >> 7); gains nothing, yet unreadable! */
- if((*b >> 7)) value = -1; else value = 0;
-
- /* Conversion engine */
- for(; b < end; b++) {
- value = (value << 8) | *b;
- }
-
- *lptr = value;
+ *lptr = asn__safe_integer_convert_helper(b, end);
return 0;
}
diff --git a/skeletons/asn_system.h b/skeletons/asn_system.h
index 2febb711..83266ef5 100644
--- a/skeletons/asn_system.h
+++ b/skeletons/asn_system.h
@@ -104,7 +104,7 @@ typedef unsigned int uint32_t;
#endif /* _WIN32 */
-#if __GNUC__ >= 3
+#if __GNUC__ >= 3 || defined(__clang__)
#ifndef GCC_PRINTFLIKE
#define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
#endif
@@ -120,6 +120,12 @@ typedef unsigned int uint32_t;
#endif
#endif
+#if defined(__clang__)
+#define CLANG_NO_SANITIZE(what) __attribute__((no_sanitize(what)))
+#else
+#define CLANG_NO_SANITIZE(what)
+#endif
+
/* Figure out if thread safety is requested */
#if !defined(ASN_THREAD_SAFE) && (defined(THREAD_SAFE) || defined(_REENTRANT))
#define ASN_THREAD_SAFE