Hi!
I wonder what you think about fixing "uninitialized variable" issues for theoretical execution paths.
What I mean with "theoretical" is that it is not assumed that parameters and global variables are restricted to the "possible" values - they could also have "impossible values".
An example:
An uninitialized variable "y" can theoretically be used in src/printing.c at line 753.
Here is the code in shortened format:
514 gdouble x, y;
561 while (count < dinfo->lines_per_page) { 686 cairo_get_current_point(cr, &x, &y); }
742 if (printing_prefs.print_line_numbers) { 752 cairo_line_to(cr, (dinfo->max_line_number_margin * dinfo->font_width) + 1, y + dinfo->line_height); /* y is last added line, we reuse it */ }
The variable "y" is initialized in the loop. If the loop is skipped the variable will not be initialized. Therefore if dinfo->lines_per_page is 0 and printing_prefs.print_line_numbers is true then there will be a "uninitialized variable" issue.
I guess there is an assumption that dinfo->lines_per_page will always be greater than 0. Perhaps that assumption is ok.
Best regards, Daniel
PS.
I wrote a simple Cppcheck plugin that searches for "uninitialized variable" in "theoretical execution paths". It will assume that all conditions can always be both true/false.
I assume that most of the reports are false positives. But if you are interested.. here is what it says for geany/src:
[src/dialogs.c:257]: (information) Suspecting that uninitialized variable is used: iter_parent [src/dialogs.c:684]: (information) Suspecting that uninitialized variable is used: resp [src/dialogs.c:740]: (information) Suspecting that uninitialized variable is used: title [src/dialogs.c:774]: (information) Suspecting that uninitialized variable is used: args [src/dialogs.c:1663]: (information) Suspecting that uninitialized variable is used: args [src/dialogs.c:1686]: (information) Suspecting that uninitialized variable is used: args [src/dialogs.c:1713]: (information) Suspecting that uninitialized variable is used: args [src/editor.c:2852]: (information) Suspecting that uninitialized variable is used: style_comment [src/editor.c:4890]: (information) Suspecting that uninitialized variable is used: mode [src/encodings.c:643]: (information) Suspecting that uninitialized variable is used: charset [src/filetypes.c:854]: (information) Suspecting that uninitialized variable is used: args [src/filetypes.c:1395]: (information) Suspecting that uninitialized variable is used: result [src/keybindings.c:1543]: (information) Suspecting that uninitialized variable is used: item [src/log.c:68]: (information) Suspecting that uninitialized variable is used: args [src/msgwindow.c:269]: (information) Suspecting that uninitialized variable is used: args [src/msgwindow.c:341]: (information) Suspecting that uninitialized variable is used: args [src/msgwindow.c:399]: (information) Suspecting that uninitialized variable is used: args [src/printing.c:753]: (information) Suspecting that uninitialized variable is used: y [src/socket.c:685]: (information) Suspecting that uninitialized variable is used: newline [src/stash.c:767]: (information) Suspecting that uninitialized variable is used: args [src/stash.c:1057]: (information) Suspecting that uninitialized variable is used: setting [src/symbols.c:205]: (information) Suspecting that uninitialized variable is used: tag_type [src/symbols.c:636]: (information) Suspecting that uninitialized variable is used: args [src/symbols.c:1917]: (information) Suspecting that uninitialized variable is used: fn_style [src/templates.c:577]: (information) Suspecting that uninitialized variable is used: args [src/tools.c:127]: (information) Suspecting that uninitialized variable is used: stock_id [src/ui_utils.c:148]: (information) Suspecting that uninitialized variable is used: args [src/ui_utils.c:885]: (information) Suspecting that uninitialized variable is used: widget_name [src/ui_utils.c:1842]: (information) Suspecting that uninitialized variable is used: args [src/ui_utils.c:2365]: (information) Suspecting that uninitialized variable is used: a [src/utils.c:1365]: (information) Suspecting that uninitialized variable is used: a [src/utils.c:2090]: (information) Suspecting that uninitialized variable is used: args [src/win32.c:713]: (information) Suspecting that uninitialized variable is used: t [src/win32.c:705]: (information) Suspecting that uninitialized variable is used: title
There could be a real issue in one of those reports but I don't know how likely that is.
I am in the process right now to analyse the results. If I see genuine problems I'll report them.