Fix some issues found by Coverity Scan
authorJulian Eisel <eiseljulian@gmail.com>
Thu, 14 May 2015 21:58:08 +0000 (23:58 +0200)
committerJulian Eisel <eiseljulian@gmail.com>
Thu, 14 May 2015 23:08:41 +0000 (01:08 +0200)
Some of them are just brain dead code, some are potential bugs.

13 files changed:
source/blender/editors/animation/anim_channels_edit.c
source/blender/editors/interface/interface_handlers.c
source/blender/editors/interface/interface_panel.c
source/blender/editors/interface/interface_regions.c
source/blender/editors/interface/interface_style.c
source/blender/editors/interface/interface_templates.c
source/blender/editors/screen/area.c
source/blender/editors/screen/screen_edit.c
source/blender/editors/space_file/filelist.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/editors/transform/transform_manipulator.c
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_keymap.c

index fd7551abab3c4d0278639f8b91116bbb235f61dd..d08a32c6e6ba0c11fde7bb837e4413d6c04749d8 100644 (file)
@@ -3055,7 +3055,7 @@ static bool select_anim_channel_keys(bAnimContext *ac, int channel_index, bool e
        ANIM_animdata_freelist(&anim_data);
 
        /* F-Curve may not have any keyframes */
-       if (fcu->bezt) {
+       if (fcu && fcu->bezt) {
                BezTriple *bezt;
 
                if (!extend) {
index d77cf8658fdecf031311512e6a88e8d7395f7b48..7e970a13e0389bc8511cff75adb9f21cb4cb821f 100644 (file)
@@ -9077,6 +9077,9 @@ static int ui_handle_menu_return_submenu(bContext *C, const wmEvent *event, uiPo
        block = ar->uiblocks.first;
 
        but = ui_but_find_active_in_region(ar);
+
+       BLI_assert(but);
+
        data = but->active;
        submenu = data->menu;
 
index 95fca10d60b8d43086107b028e82ba5eb4a49729..4b0585c34b3ee7a3f94b05d8e5ff80ed62dbf3de 100644 (file)
@@ -1215,7 +1215,6 @@ static void ui_panel_drag_collapse(bContext *C, uiPanelDragCollapseHandle *dragc
                rect.ymin = rect.ymax;
                rect.ymax = rect.ymin + PNL_HEADER;
                if (pa->flag & PNL_CLOSEDX) {
-                       rect.xmin = rect.xmin;
                        rect.xmax = rect.xmin + PNL_HEADER;
                }
 
index 9f5aa37351a6f2e2b3e8b62df39f6efdee1c0195..4b90abed82bdc46e9aebbf9dcbe3a17a452e6240 100644 (file)
@@ -1427,7 +1427,8 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but,
                if (down || top) {
                        if (dir1 == UI_DIR_UP   && top == 0)  dir1 = UI_DIR_DOWN;
                        if (dir1 == UI_DIR_DOWN && down == 0) dir1 = UI_DIR_UP;
-                       if (dir2 == UI_DIR_UP   && top == 0)  dir2 = UI_DIR_DOWN;
+                       /* dir2 is never set to UI_DIR_UP here */
+//                     if (dir2 == UI_DIR_UP   && top == 0)  dir2 = UI_DIR_DOWN;
                        if (dir2 == UI_DIR_DOWN && down == 0) dir2 = UI_DIR_UP;
                }
 
index 2f46c0906aec8d7ca1a3896e45b1f3a70e2d1ffa..4b683f3fcc2498ba89514e60d6da69fac7f4e853 100644 (file)
@@ -323,10 +323,14 @@ void UI_fontstyle_draw_simple_backdrop(
 /* XXX: read a style configure */
 uiStyle *UI_style_get(void)
 {
+#if 0
        uiStyle *style = NULL;
        /* offset is two struct uiStyle pointers */
-       /* style = BLI_findstring(&U.uistyles, "Unifont Style", sizeof(style) * 2) */;
+       style = BLI_findstring(&U.uistyles, "Unifont Style", sizeof(style) * 2);
        return (style != NULL) ? style : U.uistyles.first;
+#else
+       return U.uistyles.first;
+#endif
 }
 
 /* for drawing, scaled with DPI setting */
index ccbd30d12300270dbd349b3692f07bc3f5b0190e..2cab1aea83ff6a0ef136f7e942d73433a99e51af 100644 (file)
@@ -3214,7 +3214,6 @@ void uiTemplateList(
 
                        /* add scrollbar */
                        if (len > layoutdata.visual_items) {
-                               col = uiLayoutColumn(row, false);
                                uiDefButI(block, UI_BTYPE_SCROLL, 0, "", 0, 0, UI_UNIT_X * 0.75, UI_UNIT_Y * dyn_data->visual_height,
                                          &ui_list->list_scroll, 0, dyn_data->height - dyn_data->visual_height,
                                          dyn_data->visual_height, 0, "");
index 3a4034d9074456c27a5fa7b8a26688fa55b657ae..7fe6518134e5437ad1e117e1d962547c9071ca3d 100644 (file)
@@ -1263,16 +1263,22 @@ static void region_rect_recursive(wmWindow *win, ScrArea *sa, ARegion *ar, rcti
        if (ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) {
                ar->winrct = *remainder;
                
-               if (alignment == RGN_ALIGN_TOP)
-                       ar->winrct.ymin = ar->winrct.ymax;
-               else if (alignment == RGN_ALIGN_BOTTOM)
-                       ar->winrct.ymax = ar->winrct.ymin;
-               else if (alignment == RGN_ALIGN_RIGHT)
-                       ar->winrct.xmin = ar->winrct.xmax;
-               else if (alignment == RGN_ALIGN_LEFT)
-                       ar->winrct.xmax = ar->winrct.xmin;
-               else /* prevent winrct to be valid */
-                       ar->winrct.xmax = ar->winrct.xmin;
+               switch (alignment) {
+                       case RGN_ALIGN_TOP:
+                               ar->winrct.ymin = ar->winrct.ymax;
+                               break;
+                       case RGN_ALIGN_BOTTOM:
+                               ar->winrct.ymax = ar->winrct.ymin;
+                               break;
+                       case RGN_ALIGN_RIGHT:
+                               ar->winrct.xmin = ar->winrct.xmax;
+                               break;
+                       case RGN_ALIGN_LEFT:
+                       default:
+                               /* prevent winrct to be valid */
+                               ar->winrct.xmax = ar->winrct.xmin;
+                               break;
+               }
        }
 
        /* restore prev-split exception */
@@ -2161,7 +2167,7 @@ static void metadata_draw_imbuf(ImBuf *ibuf, rctf rect, int fontid, const bool i
 
 static float metadata_box_height_get(ImBuf *ibuf, int fontid, const bool is_top)
 {
-       char str[MAX_METADATA_STR];
+       char str[MAX_METADATA_STR] = "";
        short i, count = 0;
        const float height = BLF_height_max(fontid) + 0.1f * U.widget_unit;
 
index 3d76070f19780fe7ef9f9ebc53a89e6642edd07c..d9bd9cc4f51cd9d8180bf7e717117cf5a2c8a336 100644 (file)
@@ -1748,7 +1748,9 @@ ScrArea *ED_screen_full_newspace(bContext *C, ScrArea *sa, int type)
                        newsa = sa;
                }
        }
-       
+
+       BLI_assert(newsa);
+
        if (sa && (sa->spacetype != type)) {
                newsa->flag |= AREA_FLAG_TEMP_TYPE;
        }
index 2853ee9c053f00751149892cf028e94908d64ab7..af65149ff9c12e414025819ba2b91da159a6355e 100644 (file)
@@ -1234,7 +1234,7 @@ static void filelist_from_main(struct FileList *filelist)
 
                files = filelist->filelist;
 
-               if (!filelist->filter_data.hide_parent) {
+               if (files && !filelist->filter_data.hide_parent) {
                        memset(&(filelist->filelist[0]), 0, sizeof(struct direntry));
                        filelist->filelist[0].relname = BLI_strdup(FILENAME_PARENT);
                        filelist->filelist[0].type |= S_IFDIR;
@@ -1246,7 +1246,7 @@ static void filelist_from_main(struct FileList *filelist)
                for (id = lb->first; id; id = id->next) {
                        ok = 1;
                        if (ok) {
-                               if (!filelist->filter_data.hide_dot || id->name[2] != '.') {
+                               if (files && (!filelist->filter_data.hide_dot || id->name[2] != '.')) {
                                        memset(files, 0, sizeof(struct direntry));
                                        if (id->lib == NULL) {
                                                files->relname = BLI_strdup(id->name + 2);
index 57b417ef1d76e1841dc51b91bbf424ba253675dc..fb0f437884a107e6d1da94e7019783596f302dfd 100644 (file)
@@ -3262,6 +3262,9 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Scene *scene, View3D *v3d, ARegion *ar, in
        GPUOffScreen *ofs;
        bool draw_sky = (alpha_mode == R_ADDSKY) && v3d && (v3d->flag3 & V3D_SHOW_WORLD);
 
+       if (UNLIKELY(v3d == NULL))
+               return NULL;
+
        /* state changes make normal drawing go weird otherwise */
        glPushAttrib(GL_LIGHTING_BIT);
 
index ae8cbc721e35184dc38c2e475af7b990b92d0b19..b55a5ffbdbb2ace29d625b1d96eaabb748783dc9 100644 (file)
@@ -1056,8 +1056,6 @@ static void draw_manipulator_rotate(
                        glRotatef(90.0, 1.0, 0.0, 0.0);
                        postOrtho(ortho);
                }
-
-               if (arcs) glDisable(GL_CLIP_PLANE0);
        }
        // donut arcs
        if (arcs) {
index 69bee8bab80f9b47a4e0ee1c664e4e49152f88c0..42fc026762532f2c7da753a2f4584b26b69610e1 100644 (file)
@@ -1173,7 +1173,7 @@ static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, PointerRNA
        CTX_wm_operator_poll_msg_set(C, NULL);
 
        /* dummie test */
-       if (ot && C) {
+       if (ot) {
                wmWindow *window = CTX_wm_window(C);
 
                switch (context) {
@@ -2434,7 +2434,7 @@ void wm_event_do_handlers(bContext *C)
 
                                /* XXX hrmf, this gives reliable previous mouse coord for area change, feels bad? 
                                 * doing it on ghost queue gives errors when mousemoves go over area borders */
-                               if (doit && win->screen && win->screen->subwinactive != win->screen->mainwin) {
+                               if (doit && win->screen->subwinactive != win->screen->mainwin) {
                                        win->eventstate->prevx = event->x;
                                        win->eventstate->prevy = event->y;
                                        //printf("win->eventstate->prev = %d %d\n", event->x, event->y);
index 0ee1f9f7eebe1d7c5fbd544185be958545fc82c6..c765587b7cbdd305a168ce5c8545352534d16a18 100644 (file)
@@ -546,7 +546,7 @@ static void wm_keymap_diff(wmKeyMap *diff_km, wmKeyMap *from_km, wmKeyMap *to_km
                if (to_kmi) {
                        orig_kmi = WM_keymap_item_find_id(orig_km, kmi->id);
 
-                       if (!orig_kmi)
+                       if (!orig_kmi && addon_km)
                                orig_kmi = wm_keymap_find_item_equals(addon_km, kmi);
 
                        if (orig_kmi) {