Skip to content

Commit df3022e

Browse files
authored
Merge pull request #3 from sysprog21/cppcheck
Fix cppcheck warnings across codebase
2 parents d5ad83d + 9951c4a commit df3022e

13 files changed

Lines changed: 38 additions & 51 deletions

File tree

ports/headless.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,6 @@ bool iui_headless_save_screenshot(iui_port_ctx *ctx, const char *path)
929929
/* Adler-32 checksum */
930930
uint32_t adler = adler32(raw_data, raw_size);
931931
write_be32(zlib_data + zlib_pos, adler);
932-
zlib_pos += 4;
933932

934933
free(raw_data);
935934

src/container.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -688,10 +688,10 @@ void iui_tooltip(iui_context *ctx, const char *text)
688688
x = win.x + win.width - width;
689689

690690
/* Smart vertical positioning: check available space above and below */
691-
float space_below =
692-
(win.y + win.height) - (ctx->layout.y + ctx->row_height);
693-
float space_above = ctx->layout.y - win.y;
694691
if (y + height > win.y + win.height) {
692+
float space_below =
693+
(win.y + win.height) - (ctx->layout.y + ctx->row_height);
694+
float space_above = ctx->layout.y - win.y;
695695
/* Would overflow bottom - try flipping above if more space there */
696696
if (space_above > space_below && space_above >= height)
697697
y = ctx->layout.y - height - IUI_TOOLTIP_OFFSET;
@@ -759,10 +759,10 @@ bool iui_tooltip_rich(iui_context *ctx,
759759
x = win.x + win.width - width;
760760

761761
/* Smart vertical positioning: check available space above and below */
762-
float space_below =
763-
(win.y + win.height) - (ctx->layout.y + ctx->row_height);
764-
float space_above = ctx->layout.y - win.y;
765762
if (y + height > win.y + win.height) {
763+
float space_below =
764+
(win.y + win.height) - (ctx->layout.y + ctx->row_height);
765+
float space_above = ctx->layout.y - win.y;
766766
/* Would overflow bottom - try flipping above if more space there */
767767
if (space_above > space_below && space_above >= height)
768768
y = ctx->layout.y - height - IUI_TOOLTIP_OFFSET;

src/core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ bool iui_has_focus(const iui_context *ctx, const char *id)
874874
}
875875

876876
/* Internal: Check if widget with given ID is focused */
877-
bool iui_widget_is_focused(iui_context *ctx, uint32_t id)
877+
bool iui_widget_is_focused(const iui_context *ctx, uint32_t id)
878878
{
879879
return ctx->focused_widget_id == id && id != 0;
880880
}
@@ -1340,6 +1340,7 @@ const char *iui_a11y_state_description(uint32_t state)
13401340
APPEND_STATE(IUI_A11Y_STATE_HASPOPUP, "has popup")
13411341

13421342
#undef APPEND_STATE
1343+
(void) count; /* suppress unused-after-final-increment warning */
13431344
return buf;
13441345
}
13451346

src/dialog.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,13 @@ int iui_dialog(iui_context *ctx,
228228
iui_state_t state = iui_get_component_state(ctx, btn_rect, false);
229229

230230
/* Draw button based on position (rightmost:filled, others:text) */
231-
uint32_t bg_color = 0;
232231
uint32_t text_color = ctx->colors.primary;
233232
/* MD3 button corner radius (full rounded) */
234233
float btn_corner = IUI_SHAPE_FULL;
235234

236235
if (i == btn_count - 1) {
237236
/* Primary button (rightmost) - filled style */
238-
bg_color = ctx->colors.primary;
237+
uint32_t bg_color = ctx->colors.primary;
239238
text_color = ctx->colors.on_primary;
240239
ctx->renderer.draw_box(btn_rect, btn_corner, bg_color,
241240
ctx->renderer.user);
@@ -376,9 +375,9 @@ bool iui_fullscreen_dialog_begin(iui_context *ctx,
376375
}
377376

378377
/* Draw title after close icon */
379-
float title_x = padding + touch_target + padding * 0.5f;
380-
float title_y = (header_h - ctx->font_height) * 0.5f;
381378
if (dialog->title) {
379+
float title_x = padding + touch_target + padding * 0.5f;
380+
float title_y = (header_h - ctx->font_height) * 0.5f;
382381
iui_internal_draw_text(ctx, title_x, title_y, dialog->title,
383382
ctx->colors.on_surface);
384383
}

src/draw.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,11 @@ static void iui_divider_internal(iui_context *ctx, float left_inset)
287287
ctx->layout.y += 8.f;
288288

289289
/* MD3: 1dp height, outline_variant color */
290-
float x = ctx->layout.x + left_inset, w = ctx->layout.width - left_inset;
290+
float w = ctx->layout.width - left_inset;
291291

292292
/* Guard against negative width in narrow containers */
293293
if (w > 0.f) {
294+
float x = ctx->layout.x + left_inset;
294295
ctx->renderer.draw_box((iui_rect_t) {x, ctx->layout.y, w, 1.f}, 0.f,
295296
ctx->colors.outline_variant, ctx->renderer.user);
296297
}
@@ -537,10 +538,9 @@ iui_state_t iui_get_component_state(iui_context *ctx,
537538

538539
if (ctx->mouse_pressed & IUI_MOUSE_LEFT)
539540
return IUI_STATE_PRESSED;
540-
}
541541

542-
if (hovered)
543542
return IUI_STATE_HOVERED;
543+
}
544544

545545
return IUI_STATE_DEFAULT;
546546
}

src/fab.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,11 @@ static bool iui_fab_internal(iui_context *ctx,
5858
iui_draw_state_layer(ctx, fab_rect, corner_radius, content_color, state);
5959

6060
/* Calculate content position */
61-
float content_x = x;
6261
float center_y = y + fab_h * 0.5f;
6362

6463
if (label) {
6564
/* Extended FAB: icon (optional) + label */
66-
content_x = x + IUI_FAB_EXTENDED_PADDING;
65+
float content_x = x + IUI_FAB_EXTENDED_PADDING;
6766

6867
if (icon) {
6968
float icon_cx = content_x + icon_size * 0.5f;

src/icons.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,8 @@ void iui_draw_fab_icon(iui_context *ctx,
331331
cx + half * 0.3f, cy, stroke, color);
332332
iui_draw_line_soft(ctx, cx + half * 0.3f, cy, cx - half * 0.2f,
333333
cy + half * 0.4f, stroke, color);
334-
} else if (!strcmp(icon_name, "dot")) {
335-
/* Filled dot */
336-
iui_draw_circle_soft(ctx, cx, cy, size * 0.15f, color, 0, 0);
337334
} else {
338-
/* Default: draw a simple dot/circle for unknown icons */
335+
/* Default / "dot": draw a simple filled circle */
339336
iui_draw_circle_soft(ctx, cx, cy, size * 0.15f, color, 0, 0);
340337
}
341338
}

src/input.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -751,17 +751,16 @@ bool iui_edit_with_selection(iui_context *ctx,
751751
state->is_dragging = false;
752752
}
753753

754-
/* Handle keyboard input when focused */
754+
/* Handle keyboard input when focused and auto-scroll to keep cursor visible
755+
*/
755756
if (has_focus) {
756757
modified =
757758
iui_process_text_input_selection(ctx, buffer, buffer_size, state);
758759
/* Reset cursor blink on any key activity */
759760
if (ctx->key_pressed != IUI_KEY_NONE || ctx->char_input != 0)
760761
ctx->cursor_blink = 0.f;
761-
}
762762

763-
/* Auto-scroll to keep cursor visible */
764-
if (has_focus) {
763+
/* Auto-scroll to keep cursor visible */
765764
float cursor_x_in_text =
766765
textfield_get_width_to_pos(ctx, buffer, state->cursor, false);
767766
if (cursor_x_in_text < state->scroll_offset)
@@ -990,7 +989,8 @@ iui_textfield_result iui_textfield_with_selection(
990989
has_focus = false;
991990
state->is_dragging = false;
992991
}
993-
} else if (opts.disabled && has_focus) {
992+
} else if (has_focus) {
993+
/* Widget is disabled but still has focus - clear it */
994994
ctx->focused_edit = NULL;
995995
has_focus = false;
996996
}
@@ -1217,15 +1217,11 @@ bool iui_switch(iui_context *ctx,
12171217
}
12181218
}
12191219

1220-
/* Apply focus state layer */
1220+
/* Apply focus state layer and draw focus ring when focused */
12211221
if (is_focused) {
12221222
uint32_t focus_layer =
12231223
iui_state_layer(ctx->colors.primary, IUI_STATE_FOCUS_ALPHA);
12241224
track_color = iui_blend_color(track_color, focus_layer);
1225-
}
1226-
1227-
/* Draw focus ring when focused */
1228-
if (is_focused) {
12291225
iui_draw_focus_ring(ctx, track_rect, corner);
12301226
}
12311227

@@ -1525,16 +1521,14 @@ bool iui_dropdown(iui_context *ctx, const iui_dropdown_options *options)
15251521
}
15261522

15271523
/* Draw floating label */
1528-
float label_y;
1529-
uint32_t label_color =
1530-
options->disabled
1531-
? iui_state_layer(ctx->colors.on_surface_variant,
1532-
IUI_STATE_DISABLE_ALPHA)
1533-
: (is_open ? ctx->colors.primary : ctx->colors.on_surface_variant);
1534-
15351524
if (options->label) {
1525+
uint32_t label_color =
1526+
options->disabled ? iui_state_layer(ctx->colors.on_surface_variant,
1527+
IUI_STATE_DISABLE_ALPHA)
1528+
: (is_open ? ctx->colors.primary
1529+
: ctx->colors.on_surface_variant);
15361530
/* Label floats above when there's a selection */
1537-
label_y = field_rect.y + 8.f;
1531+
float label_y = field_rect.y + 8.f;
15381532
iui_internal_draw_text(ctx, field_rect.x + padding, label_y,
15391533
options->label, label_color);
15401534
}

src/internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ void iui_draw_fab_icon(iui_context *ctx,
988988
float cx,
989989
float cy,
990990
float size,
991-
const char *icon,
991+
const char *icon_name,
992992
uint32_t color);
993993

994994
/* Vector font rendering (implemented in core.c) */
@@ -1079,7 +1079,7 @@ bool iui_register_focusable(iui_context *ctx,
10791079
iui_rect_t bounds,
10801080
float corner);
10811081
void iui_process_focus_navigation(iui_context *ctx);
1082-
bool iui_widget_is_focused(iui_context *ctx, uint32_t id);
1082+
bool iui_widget_is_focused(const iui_context *ctx, uint32_t id);
10831083

10841084
/* Layout internal functions (iui_layout.c) */
10851085

src/layout.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,8 @@ void iui_row(iui_context *ctx, int items, const float *widths, float height)
9595
return;
9696

9797
/* End previous row if any */
98-
if (ctx->in_row) {
98+
if (ctx->in_row)
9999
ctx->layout.y = ctx->row.next_row_y;
100-
ctx->in_row = false;
101-
}
102100

103101
ctx->in_row = true;
104102
ctx->row.item_count = items;

0 commit comments

Comments
 (0)