From 6f59d4c8bb135eca9e3684853e6bb589143e40ff Mon Sep 17 00:00:00 2001 From: Jonathan Wilkes <jon.w.wilkes@gmail.com> Date: Sun, 25 Aug 2019 23:59:32 -0400 Subject: [PATCH] fix undefined behavior with the ++ operator --- externals/ggee/control/serial_bird.c | 4 ++-- externals/ggee/control/serial_ms.c | 3 ++- externals/ggee/control/serial_mt.c | 3 ++- externals/jasch_lib/detox/detox.c | 13 ++++++++----- externals/moonlib/tabsort.c | 5 ++++- externals/moonlib/tabsort2.c | 5 ++++- 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/externals/ggee/control/serial_bird.c b/externals/ggee/control/serial_bird.c index 6423dc714..24ff5da17 100644 --- a/externals/ggee/control/serial_bird.c +++ b/externals/ggee/control/serial_bird.c @@ -128,8 +128,8 @@ static void serial_bird_float( t_serial_bird* x,t_floatarg f) /* post("posx %d, posy %d",x->x_posx,x->x_posy);*/ outlet_list(x->x_obj.ob_outlet,&s_list, ac, at); } - - x->x_count = (++x->x_count)%(x->x_maxcount); + x->x_count++; + x->x_count = x->x_count % x->x_maxcount; } static void serial_bird_poll( t_serial_bird* x) diff --git a/externals/ggee/control/serial_ms.c b/externals/ggee/control/serial_ms.c index b012fdf63..e06ce341a 100644 --- a/externals/ggee/control/serial_ms.c +++ b/externals/ggee/control/serial_ms.c @@ -69,7 +69,8 @@ static void serial_ms_float( t_serial_ms* x,t_floatarg f) x->x_c[x->x_count] = (char) f; - x->x_count = (++x->x_count)%3; + x->x_count++; + x->x_count = x->x_count % 3; if (x->x_count==2) { dx= (signed char)(((x->x_c[0] & 0x03) << 6) | diff --git a/externals/ggee/control/serial_mt.c b/externals/ggee/control/serial_mt.c index 02a1aac63..2b4e24a1e 100644 --- a/externals/ggee/control/serial_mt.c +++ b/externals/ggee/control/serial_mt.c @@ -31,7 +31,8 @@ static void serial_mt_float( t_serial_mt* x,t_floatarg f) x->x_c[x->x_count] = (char) f; - x->x_count = (++x->x_count)%3; + x->x_count++; + x->x_count = x->x_count % 3; if (x->x_count==2) { dx= (signed char)(((x->x_c[0] & 0x03) << 6) | diff --git a/externals/jasch_lib/detox/detox.c b/externals/jasch_lib/detox/detox.c index 1558ba077..5a393e5d5 100644 --- a/externals/jasch_lib/detox/detox.c +++ b/externals/jasch_lib/detox/detox.c @@ -229,7 +229,7 @@ void detox_reset(t_detox *x) { short i; x->t_treecount = 0; - for(i=0;i<256; i++) x->t_tree[i].a_w.w_symbol = ps_nothing; + for (i = 0; i < 256; i++) x->t_tree[i].a_w.w_symbol = ps_nothing; } void detox_debug(t_detox *x, float f) @@ -302,7 +302,7 @@ void detox_action(t_detox *x) if ((local[0] != '<') || (local[j-1] != '>')) { tagtype = 0; // not a well formed tag - if(x->t_debug) post("tagtype 0"); + if (x->t_debug) post("tagtype 0"); goto content; } if ((local[1] == '?') || (local[1] == '!')) @@ -536,7 +536,8 @@ attributes: if (x->t_debug) post("first quotetype found is %c", quotetype[0]); // copy end pointer to pos of startpointer + 1, // right after the quote - ptr2 = ++ptr1; + ptr1++; + ptr2 = ptr1; while (ptr2 != NULL) { // looking for next quote of stored type if (ptr2[0] == quotetype[0]) @@ -665,7 +666,8 @@ attributes: post("first quotetype found is %c", quotetype[0]); // copy end pointer to pos of startpointer + 1, // right after the quote - ptr2 = ++ptr1; + ptr1++; + ptr2 = ptr1; while (ptr2 != NULL) { // looking for next quote of stored type if (ptr2[0] == quotetype[0]) @@ -720,7 +722,8 @@ attributes: outlet_anything(x->s_outlet, x->t_attrpair[0].a_w.w_symbol, 1, &x->t_attrpair[1]); - ptr1 = ++ptr2; // move start pointer to end of atrr-content + ptr2++; + ptr1 = ptr2; // move start pointer to end of attr-content while (ptr1 != NULL) { // find next non-whitespace char if (ptr1[0] != ' ') diff --git a/externals/moonlib/tabsort.c b/externals/moonlib/tabsort.c index 165842683..2e3e3a719 100644 --- a/externals/moonlib/tabsort.c +++ b/externals/moonlib/tabsort.c @@ -89,7 +89,10 @@ static void tabsort_float(t_tabsort *x, t_floatarg n) if(n>n2) n=n2; - for(i=0; i<n; vec2[i]=i++); + for(i = 0; i < n; i++) + { + vec2[i] = i; + } for(i=0; i<n-1; i++) for(j=n-1; j>i; j--) diff --git a/externals/moonlib/tabsort2.c b/externals/moonlib/tabsort2.c index 67232de25..7f19a3e0c 100644 --- a/externals/moonlib/tabsort2.c +++ b/externals/moonlib/tabsort2.c @@ -111,7 +111,10 @@ static void tabsort2_float(t_tabsort2 *x, t_floatarg n) if(n>n2) n=n2; if(n>n3) n=n3; - for(i=0; i<n; vec3[i]=i++); + for(i = 0; i < n; i++) + { + vec3[i] = i; + } for(i=0; i<n-1; i++) for(j=n-1; j>i; j--) -- GitLab