]> git.earman.xyz Git - sensor-watch.git/commitdiff
Tally face: fix build warnings (#43)
authorDaniel Bergman <danber@gmail.com>
Mon, 7 Jul 2025 23:14:07 +0000 (01:14 +0200)
committerGitHub <noreply@github.com>
Mon, 7 Jul 2025 23:14:07 +0000 (19:14 -0400)
Clamp tally index values in print_tally function to ensure they remain within defined limits, silencing compiler warnings

watch-faces/complication/tally_face.c

index c2d202e6db323443e9828e6df0fa4f6e455a23cb..deb5b878a737f8dc222881c1124c25ebc0734c12 100644 (file)
@@ -195,12 +195,18 @@ bool tally_face_loop(movement_event_t event, void *context) {
 // print tally index at the center of display.
 void print_tally(tally_state_t *state, bool sound_on) {
     char buf[6];
+    int display_val = (int)(state->tally_idx);
+    
+    // Clamp to limits
+    if (display_val > TALLY_FACE_MAX) display_val = TALLY_FACE_MAX;
+    if (display_val < TALLY_FACE_MIN) display_val = TALLY_FACE_MIN;
+    
     if (sound_on)
         watch_set_indicator(WATCH_INDICATOR_BELL);
     else
         watch_clear_indicator(WATCH_INDICATOR_BELL);
     watch_display_text_with_fallback(WATCH_POSITION_TOP, "TALLY", "TA");
-    sprintf(buf, "%4d", (int)(state->tally_idx));
+    sprintf(buf, "%4d", display_val);
     watch_display_text(WATCH_POSITION_BOTTOM, buf);
 }