Ticket #3431: mc-indroduce-wswitch-default-check.patch
File mc-indroduce-wswitch-default-check.patch, 24.2 KB (added by and, 10 years ago) |
---|
-
m4.include/mc-cflags.m4
introduce -Wswitch-default check because switch cases should almost always have a default case 1. to 'catch' an unexpected value 2. to handle 'default' actions, where the cases are for special behavior 3. to show someone reading your code that you've covered that case please cross check for default stub case and add code comment at default case Signed-off-by: Andreas Mohr <and@gmx.li>
a b 71 71 dnl MC_CHECK_ONE_CFLAG([-Wstrict-aliasing]) 72 72 MC_CHECK_ONE_CFLAG([-Wstrict-prototypes]) 73 73 MC_CHECK_ONE_CFLAG([-Wswitch]) 74 MC_CHECK_ONE_CFLAG([-Wswitch-default]) 74 75 MC_CHECK_ONE_CFLAG([-Wtype-limits]) 75 76 MC_CHECK_ONE_CFLAG([-Wundef]) 76 77 MC_CHECK_ONE_CFLAG([-Wuninitialized]) -
lib/charsets.c
a b 454 454 case ESTR_FAILURE: 455 455 ch = '.'; 456 456 break; 457 default: 458 break; 457 459 } 458 460 str_close_conv (conv); 459 461 } … … 489 491 case ESTR_FAILURE: 490 492 ch = '.'; 491 493 break; 494 default: 495 break; 492 496 } 493 497 return ch; 494 498 } … … 523 527 case ESTR_FAILURE: 524 528 ch = '.'; 525 529 break; 530 default: 531 break; 526 532 } 527 533 return ch; 528 534 } … … 565 571 case ESTR_FAILURE: 566 572 ch = '.'; 567 573 break; 574 default: 575 break; 568 576 } 569 577 str_close_conv (conv); 570 578 } -
lib/filehighlight/get-color.c
a b 197 197 if (mc_fhl_is_special_door (fe)) 198 198 my_color = TRUE; 199 199 break; 200 default: 201 break; 200 202 } 201 203 202 204 return (my_color) ? mc_filter->color_pair_index : -1; … … 250 252 if (ret > 0) 251 253 return -ret; 252 254 break; 255 default: 256 break; 253 257 } 254 258 } 255 259 return NORMAL_COLOR; -
lib/lock.c
a b 251 251 g_free (msg); 252 252 goto ret; 253 253 break; /* FIXME: unneeded? */ 254 default: 255 break; 254 256 } 255 257 g_free (msg); 256 258 } -
lib/search/glob.c
a b 146 146 if (!escaped_mode) 147 147 g_string_append_c (buff, '\\'); 148 148 break; 149 default: 150 break; 149 151 } 150 152 g_string_append_c (buff, c); 151 153 escaped_mode = FALSE; -
lib/serialize.c
a b 330 330 g_free (current_value); 331 331 current_status = WAIT_GROUP; 332 332 break; 333 default: 334 break; 333 335 } 334 336 } 335 337 g_free (current_group); -
lib/strutil/strescape.c
a b 81 81 case '\0': 82 82 g_string_append (ret, "\\0"); 83 83 continue; 84 default: 85 break; 84 86 } 85 87 } 86 88 … … 145 147 case '0': 146 148 g_string_append_c (ret, '\0'); 147 149 continue; 150 default: 151 break; 148 152 } 149 153 } 150 154 -
lib/strutil/strutil8bit.c
a b 286 286 case J_RIGHT: 287 287 ident = width - length; 288 288 break; 289 default: 290 break; 289 291 } 290 292 291 293 if ((int) remain <= ident) … … 330 332 case J_RIGHT: 331 333 ident = length - width; 332 334 break; 335 default: 336 break; 333 337 } 334 338 335 339 pos += ident; -
lib/strutil/strutilascii.c
a b 230 230 case J_RIGHT: 231 231 ident = width - length; 232 232 break; 233 default: 234 break; 233 235 } 234 236 235 237 /* add space before text */ … … 289 291 case J_RIGHT: 290 292 ident = length - width; 291 293 break; 294 default: 295 break; 292 296 } 293 297 294 298 /* copy substring text, substring start from ident and take width -
lib/strutil/strutilutf8.c
a b 619 619 case J_RIGHT: 620 620 tool.ident = width - pre_form->width; 621 621 break; 622 default: 623 break; 622 624 } 623 625 624 626 utf8_tool_insert_space (&tool, tool.ident); … … 647 649 case J_RIGHT: 648 650 tool.ident = width - pre_form->width; 649 651 break; 652 default: 653 break; 650 654 } 651 655 652 656 utf8_tool_skip_chars_to (&tool, 0); -
lib/strutil/xstrtol.c
a b 163 163 base = 1000; 164 164 suffixes++; 165 165 break; 166 default: 167 break; 166 168 } 167 169 } 168 170 -
lib/tty/color-ncurses.c
a b 169 169 COLOR_WHITE, COLOR_BLACK, 170 170 COLOR_WHITE, COLOR_BLACK, A_UNDERLINE); 171 171 break; 172 default: 173 break; 172 174 } 173 175 } 174 176 else -
lib/tty/key.c
a b 1123 1123 case KEY_KP_MULTIPLY: 1124 1124 c = '*'; 1125 1125 break; 1126 default: 1127 break; 1126 1128 } 1127 1129 1128 1130 return (mod | c); -
lib/tty/color-slang.c
a b 165 165 mc_tty_color_pair_init_special (mc_color_pair, 166 166 "white", "black", "white", "black", SLTT_ULINE_MASK); 167 167 break; 168 default: 169 break; 168 170 } 169 171 } 170 172 else -
lib/util.c
a b 296 296 if (ret->len == 0) 297 297 g_string_append_c (ret, '\\'); 298 298 break; 299 default: 300 break; 299 301 } 300 302 g_string_append_c (ret, *s); 301 303 } … … 773 775 r = new_r + 1; 774 776 goto osc_out; 775 777 } 778 default: 779 break; 776 780 } 777 781 } 778 782 osc_out: … … 854 858 return COMPRESSION_BZIP; 855 859 case 'h': 856 860 return COMPRESSION_BZIP2; 861 default: 862 break; 857 863 } 858 864 } 859 865 … … 901 907 return "/ulzma" VFS_PATH_URL_DELIMITER; 902 908 case COMPRESSION_XZ: 903 909 return "/uxz" VFS_PATH_URL_DELIMITER; 910 default: 911 break; 904 912 } 905 913 /* Should never reach this place */ 906 914 fprintf (stderr, "Fatal: decompress_extension called with an unknown argument\n"); -
lib/vfs/direntry.c
a b 640 640 case SEEK_END: 641 641 offset += size; 642 642 break; 643 default: 644 break; 643 645 } 644 646 if (offset < 0) 645 647 FH->pos = 0; … … 822 824 case VFS_SETCTL_FLUSH: 823 825 ((struct vfs_s_subclass *) path_element->class->data)->flush = 1; 824 826 return 1; 827 default: 828 break; 825 829 } 826 830 return 0; 827 831 } -
lib/vfs/path.c
a b 309 309 case 'r': 310 310 path_element->port = 2; 311 311 break; 312 default: 313 break; 312 314 } 313 315 } 314 316 } -
lib/vfs/utilvfs.c
a b 334 334 case 'r': 335 335 path_element->port = 2; 336 336 break; 337 default: 338 break; 337 339 } 338 340 } 339 341 } -
src/vfs/smbfs/helpers/lib/kanji.c
a b 673 673 *out++ = jis_kso; 674 674 shifted = _KJ_KANJI; 675 675 break; 676 default: 677 break; 676 678 } 677 679 code = sjis2jis ((int) from[0] & 0xff, (int) from[1] & 0xff); 678 680 *out++ = (code >> 8) & 0xff; … … 689 691 *out++ = jis_ksi; 690 692 shifted = _KJ_ROMAN; 691 693 break; 694 default: 695 break; 692 696 } 693 697 *out++ = *from++; 694 698 } … … 701 705 *out++ = jis_ksi; 702 706 shifted = _KJ_ROMAN; 703 707 break; 708 default: 709 break; 704 710 } 705 711 *out = 0; 706 712 if (overwrite) … … 819 825 *out++ = jis_kso; 820 826 shifted = _KJ_KANJI; 821 827 break; 828 default: 829 break; 822 830 } 823 831 code = sjis2jis ((int) from[0] & 0xff, (int) from[1] & 0xff); 824 832 *out++ = (code >> 8) & 0xff; … … 837 845 *out++ = jis_so; 838 846 shifted = _KJ_KANA; 839 847 break; 848 default: 849 break; 840 850 } 841 851 *out++ = ((int) *from++) - 0x80; 842 852 } … … 854 864 *out++ = jis_ksi; 855 865 shifted = _KJ_ROMAN; 856 866 break; 867 default: 868 break; 857 869 } 858 870 *out++ = *from++; 859 871 } … … 868 880 *out++ = jis_si1; 869 881 *out++ = jis_ksi; 870 882 break; 883 default: 884 break; 871 885 } 872 886 *out = 0; 873 887 if (overwrite) … … 980 994 *out++ = jis_so2; 981 995 shifted = _KJ_KANJI; 982 996 break; 997 default: 998 break; 983 999 } 984 1000 code = sjis2jis ((int) from[0] & 0xff, (int) from[1] & 0xff); 985 1001 *out++ = (code >> 8) & 0xff; … … 997 1013 *out++ = junet_kana2; 998 1014 shifted = _KJ_KANA; 999 1015 break; 1016 default: 1017 break; 1000 1018 } 1001 1019 *out++ = ((int) *from++) - 0x80; 1002 1020 } … … 1011 1029 *out++ = jis_si2; 1012 1030 shifted = _KJ_ROMAN; 1013 1031 break; 1032 default: 1033 break; 1014 1034 } 1015 1035 *out++ = *from++; 1016 1036 } … … 1023 1043 *out++ = jis_si1; 1024 1044 *out++ = jis_si2; 1025 1045 break; 1046 default: 1047 break; 1026 1048 } 1027 1049 *out = 0; 1028 1050 if (overwrite) -
src/vfs/smbfs/helpers/lib/util_sock.c
a b 174 174 socket_options[i].option, (char *) &on, sizeof (int)); 175 175 } 176 176 break; 177 default: 178 break; 177 179 } 178 180 179 181 if (ret != 0) -
src/vfs/smbfs/helpers/libsmb/clientgen.c
a b 2142 2142 return (ret); 2143 2143 } 2144 2144 return (SVAL (p, 0)); 2145 default: 2146 break; 2145 2147 } 2146 2148 2147 2149 DEBUG (1, ("Unknown long filename format %d\n", level)); … … 2277 2279 pstrcpy (mask, p + ff_lastname + 1); 2278 2280 ff_resume_key = 0; 2279 2281 break; 2282 default: 2283 break; 2280 2284 } 2281 2285 } 2282 2286 else … … 2664 2668 return ENOTDIR; 2665 2669 case NT_STATUS_OBJECT_NAME_COLLISION: 2666 2670 return EEXIST; 2671 default: 2672 break; 2667 2673 } 2668 2674 2669 2675 /* for all other cases - a default code */ … … 2698 2704 return EBUSY; 2699 2705 case ERRlock: 2700 2706 return EBUSY; 2707 default: 2708 break; 2701 2709 } 2702 2710 } 2703 2711 if (rcls == ERRSRV) … … 2714 2722 return ENODEV; 2715 2723 case ERRinvnetname: 2716 2724 return ENODEV; 2725 default: 2726 break; 2717 2727 } 2718 2728 } 2719 2729 /* for other cases */ -
src/vfs/smbfs/helpers/param/loadparm.c
a b 2080 2080 break; 2081 2081 case P_SEP: 2082 2082 break; 2083 default: 2084 break; 2083 2085 } 2084 2086 2085 2087 return (True); … … 2142 2144 } 2143 2145 case P_SEP: 2144 2146 break; 2147 default: 2148 break; 2145 2149 } 2146 2150 return (False); 2147 2151 } … … 2381 2385 break; 2382 2386 case P_SEP: 2383 2387 break; 2388 default: 2389 break; 2384 2390 } 2385 2391 } 2386 2392 defaults_saved = True; -
src/vfs/smbfs/smbfs.c
a b 572 572 case STYPE_IPC: 573 573 typestr = "IPC"; 574 574 break; 575 default: 576 break; 575 577 } 576 578 DEBUG (3, ("\t%-15.15s%-10.10s%s\n", name, typestr, comment)); 577 579 } … … 1860 1862 } 1861 1863 info->nread = size + offset; 1862 1864 break; 1865 default: 1866 break; 1863 1867 } 1864 1868 1865 1869 return info->nread; … … 2030 2034 case VFS_SETCTL_LOGFILE: 2031 2035 smbfs_set_debugf ((const char *) arg); 2032 2036 break; 2037 default: 2038 break; 2033 2039 } 2034 2040 return 0; 2035 2041 } -
lib/widget/dialog.c
a b 242 242 case SELECT_PREV: 243 243 h->current = dlg_widget_prev (h, h->current); 244 244 break; 245 default: 246 break; 245 247 } 246 248 } 247 249 while (h->current != w /* && (WIDGET (h->current->data)->options & W_DISABLED) == 0 */ ); -
lib/widget/input_complete.c
a b 659 659 if (!found) 660 660 MC_PTR_FREE (cur_word); 661 661 } 662 default: 663 break; 662 664 } 663 665 664 666 if (found == NULL) … … 1088 1090 /* fallthrough */ 1089 1091 case -2: 1090 1092 return MSG_HANDLED; 1093 default: 1094 break; 1091 1095 } 1092 1096 1093 1097 for (i = 0, e = listbox_get_first_link (LISTBOX (h->current->data)); -
lib/widget/menu.c
a b 484 484 case XCTRL ('f'): 485 485 menubar_right (menubar); 486 486 return 1; 487 default: 488 break; 487 489 } 488 490 489 491 if (!menubar->is_dropped) … … 554 556 case XCTRL ('p'): 555 557 menubar_up (menubar); 556 558 break; 559 default: 560 break; 557 561 } 558 562 } 559 563 -
lib/widget/radio.c
a b 105 105 r->pos++; 106 106 return MSG_HANDLED; 107 107 } 108 default: 109 break; 108 110 } 109 111 return MSG_NOT_HANDLED; 110 112 -
src/background.c
a b 316 316 case 4: 317 317 result = routine.have_ctx4 (Background, data[0], data[1], data[2], data[3]); 318 318 break; 319 default: 320 break; 319 321 } 320 322 else 321 323 switch (argc) … … 336 338 result = 337 339 routine.non_have_ctx4 (ctx, Background, data[0], data[1], data[2], data[3]); 338 340 break; 341 default: 342 break; 339 343 } 340 344 341 345 /* Send the result code and the value for shared variables */ -
src/consaver/cons.saver.c
a b 267 267 case CONSOLE_CONTENTS: 268 268 send_contents (buffer + 4, winsz.ws_col, winsz.ws_row); 269 269 break; 270 default: 271 break; 270 272 } 271 273 272 274 if (write (1, &console_flag, 1) != 1) -
src/diffviewer/ydiff.c
a b 2004 2004 case CHG_CH: 2005 2005 res = DIFF_CHG; 2006 2006 break; 2007 default: 2008 break; 2007 2009 } 2008 2010 while (pos > 0 && ((DIFFLN *) & g_array_index (a0, DIFFLN, pos))->ch != EQU_CH) 2009 2011 pos--; … … 2239 2241 case DIFF_CHG: 2240 2242 dview_replace_hunk (dview, merge_file, from1, to1, from2, to2, merge_direction); 2241 2243 break; 2244 default: 2245 break; 2242 2246 } 2243 2247 fflush (merge_file); 2244 2248 fclose (merge_file); -
src/editor/edit.c
a b 1168 1168 case COLUMN_OFF: 1169 1169 edit->column_highlight = 0; 1170 1170 break; 1171 default: 1172 break; 1171 1173 } 1172 1174 if (ac >= 256 && ac < 512) 1173 1175 edit_insert_ahead (edit, ac - 256); … … 1251 1253 case COLUMN_OFF: 1252 1254 edit->column_highlight = 0; 1253 1255 break; 1256 default: 1257 break; 1254 1258 } 1255 1259 if (ac >= 256 && ac < 512) 1256 1260 edit_insert_ahead (edit, ac - 256); … … 1913 1917 break; 1914 1918 case LB_ASIS: /* default without changes */ 1915 1919 break; 1920 default: 1921 break; 1916 1922 } 1917 1923 } 1918 1924 } … … 3404 3410 edit->column_highlight = 0; 3405 3411 edit_mark_cmd (edit, TRUE); 3406 3412 } 3413 default: 3414 break; 3407 3415 } 3408 3416 3409 3417 switch (command) … … 3429 3437 case CK_MarkLeft: 3430 3438 case CK_MarkRight: 3431 3439 edit->force |= REDRAW_CHAR_ONLY; 3440 default: 3441 break; 3432 3442 } 3433 3443 3434 3444 /* basic cursor key commands */ … … 3961 3971 case CK_DeleteToEnd: 3962 3972 format_paragraph (edit, FALSE); 3963 3973 edit->force |= REDRAW_PAGE; 3974 default: 3975 break; 3964 3976 } 3965 3977 } 3966 3978 } -
src/editor/editcmd.c
a b 2879 2879 case 2: /* Cancel quit */ 2880 2880 case -1: /* Esc */ 2881 2881 return FALSE; 2882 default: 2883 break; 2882 2884 } 2883 2885 2884 2886 return TRUE; -
src/editor/editwidget.c
a b 1459 1459 break; 1460 1460 } 1461 1461 break; 1462 default: 1463 break; 1462 1464 } 1463 1465 1464 1466 return ret; -
src/editor/etags.c
a b 153 153 *short_name = shortdef; 154 154 *line = atol (linedef); 155 155 return TRUE; 156 default: 157 break; 156 158 } 157 159 buf++; 158 160 c = *buf; … … 250 252 } 251 253 } 252 254 break; 255 default: 256 break; 253 257 } 254 258 } 255 259 -
src/filemanager/achown.c
a b 303 303 h->ret_value = parm; 304 304 dlg_stop (h); 305 305 } 306 default: 307 break; 306 308 } 307 309 308 310 default: … … 615 617 dlg_one_down (h); 616 618 } 617 619 break; 620 default: 621 break; 618 622 } 619 623 return MSG_NOT_HANDLED; 620 624 … … 888 892 889 893 case B_SKIP: 890 894 break; 895 default: 896 break; 891 897 } 892 898 893 899 if (current_panel->marked && result != B_CANCEL) -
src/filemanager/chmod.c
a b 541 541 542 542 apply_mask (&sf_stat); 543 543 break; 544 default: 545 break; 544 546 } 545 547 546 548 if (current_panel->marked != 0 && result != B_CANCEL) -
src/filemanager/chown.c
a b 436 436 apply_chowns (new_user, new_group); 437 437 break; 438 438 } 439 default: 440 break; 439 441 } /* switch */ 440 442 441 443 if (current_panel->marked && ch_dlg->ret_value != B_CANCEL) -
src/filemanager/command.c
a b 181 181 state = copy_sym; 182 182 break; 183 183 } 184 default: 185 break; 184 186 } 185 187 } 186 188 -
src/filemanager/hotlist.c
a b 1538 1538 case HL_TYPE_DOTDOT: 1539 1539 /* do nothing */ 1540 1540 break; 1541 default: 1542 break; 1541 1543 } 1542 1544 } 1543 1545 -
src/filemanager/layout.c
a b 1022 1022 1023 1023 mcview_load ((struct mcview_struct *) new_widget, 0, file_name, 0); 1024 1024 break; 1025 default: 1026 break; 1025 1027 } 1026 1028 1027 1029 if (type != view_listing) -
src/filemanager/panel.c
a b 3376 3376 /* reset state of marks flag */ 3377 3377 state_mark = -1; 3378 3378 break; 3379 default: 3380 break; 3379 3381 } 3380 3382 switch (command) 3381 3383 { … … 3525 3527 case CK_SortByMTime: 3526 3528 panel_set_sort_type_by_id (panel, "mtime"); 3527 3529 break; 3530 default: 3531 break; 3528 3532 } 3529 3533 return res; 3530 3534 } -
src/filemanager/panelize.c
a b 549 549 return; 550 550 } 551 551 break; 552 default: 553 break; 552 554 } 553 555 554 556 panelize_done (); -
src/filemanager/treestore.c
a b 192 192 case '\\': 193 193 *q = '\\'; 194 194 break; 195 default: 196 break; 195 197 } 196 198 } 197 199 *q = *p; -
src/filemanager/usermenu.c
a b 905 905 result = g_string_free (block, FALSE); 906 906 goto ret; 907 907 } /* sub case block */ 908 default: 909 break; 908 910 } /* switch */ 909 911 result = g_strdup ("% "); 910 912 result[1] = c; -
src/learn.c
a b 218 218 case 'k': 219 219 dlg_one_up (learn_dlg); 220 220 return TRUE; 221 default: 222 break; 221 223 } 222 224 223 225 /* Prevent from disappearing if a non-defined sequence is pressed -
src/subshell.c
a b 335 335 case FISH: 336 336 execl (mc_global.tty.shell, "fish", (char *) NULL); 337 337 break; 338 default: 339 break; 338 340 } 339 341 340 342 /* If we get this far, everything failed miserably */ … … 770 772 mc_global.tty.use_subshell = FALSE; 771 773 mc_global.midnight_shutdown = TRUE; 772 774 return; 775 default: 776 break; 773 777 } 774 778 775 779 /* Take the current (hopefully pristine) tty mode and make */ … … 897 901 "function fish_prompt; echo $PWD>&%d; fish_prompt_mc; kill -STOP %%self; end\n", 898 902 subshell_pipe[WRITE]); 899 903 break; 900 904 default: 905 break; 901 906 } 902 907 write_all (mc_global.tty.subshell_pty, precmd, strlen (precmd)); 903 908 -
src/vfs/cpio/cpio.c
a b 751 751 continue; 752 752 case STATUS_TRAIL: 753 753 break; 754 default: 755 break; 754 756 } 755 757 break; 756 758 } -
src/vfs/fish/fish.c
a b 829 829 ST.st_rdev = makedev (maj, min); 830 830 #endif 831 831 } 832 default: 833 break; 832 834 } 833 835 } 834 836 -
src/vfs/ftpfs/ftpfs.c
a b 410 410 if (string_buf != NULL) 411 411 g_strlcpy (string_buf, answer, string_len); 412 412 return code / 100; 413 default: 414 break; 413 415 } 414 416 } 415 417 } … … 1145 1147 case AF_INET6: 1146 1148 ((struct sockaddr_in6 *) sa)->sin6_port = port; 1147 1149 break; 1150 default: 1151 break; 1148 1152 } 1149 1153 1150 1154 return (connect (my_socket, (struct sockaddr *) sa, *salen) < 0) ? 0 : 1; -
src/vfs/sfs/sfs.c
a b 188 188 case '%': 189 189 COPY_CHAR; 190 190 continue; 191 default: 192 break; 191 193 } 192 194 if (ptr != NULL) 193 195 { -
src/vfs/sftpfs/file.c
a b 399 399 } 400 400 file_handler->pos = file_handler->ino->st.st_size - offset; 401 401 break; 402 default: 403 break; 402 404 } 403 405 404 406 file_handler_data = (sftpfs_file_handler_data_t *) file_handler->data; -
src/vfs/tar/tar.c
a b 423 423 st->st_rdev = 424 424 (tar_from_oct (8, header->header.devmajor) << 8) | 425 425 tar_from_oct (8, header->header.devminor); 426 default: 427 break; 426 428 } 427 429 default: 428 430 st->st_uid = tar_from_oct (8, header->header.uid); … … 800 802 801 803 case STATUS_EOF: 802 804 return 0; 805 default: 806 break; 803 807 } 804 808 805 809 /* Record of zeroes */ … … 808 812 /* exit from loop */ 809 813 case STATUS_EOF: /* End of archive */ 810 814 break; 815 default: 816 break; 811 817 } 812 818 break; 813 819 } -
src/viewer/coord_cache.c
a b 417 417 case NROFF_BACKSPACE: 418 418 nroff_state = NROFF_CONTINUATION; 419 419 break; 420 default: 421 break; 420 422 } 421 423 422 424 /* Cache entries must guarantee that for each i < j, -
src/viewer/datasource.c
a b 177 177 break; 178 178 case DS_NONE: 179 179 break; 180 default: 181 break; 180 182 } 181 183 182 184 if (str == NULL) -
src/viewer/inlines.h
a b 109 109 return mcview_get_byte_string (view, offset, retval); 110 110 case DS_NONE: 111 111 return mcview_get_byte_none (view, offset, retval); 112 default: 113 break; 112 114 } 113 115 #ifdef HAVE_ASSERT_H 114 116 assert (!"Unknown datasource type");