fixes for errors/warnings found with cppcheck
authorCampbell Barton <ideasman42@gmail.com>
Sat, 26 Dec 2009 20:23:13 +0000 (20:23 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 26 Dec 2009 20:23:13 +0000 (20:23 +0000)
15 files changed:
source/blender/avi/intern/avi.c
source/blender/blenkernel/intern/customdata_file.c
source/blender/blenkernel/intern/script.c
source/blender/blenlib/intern/fileops.c
source/blender/blenlib/intern/storage.c
source/blender/editors/mesh/editmesh_loop.c
source/blender/editors/physics/particle_edit.c
source/blender/editors/space_buttons/buttons_context.c
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/imbuf/intern/readimage.c
source/blender/imbuf/intern/targa.c
source/blender/python/BPY_extern.h
source/blender/python/intern/stubs.c
source/blender/render/intern/source/convertblender.c

index 005c05dec1d54a959cda4f33717a8728735b3796..2aedddfb97e14603887e0af4cf0a748177938876 100644 (file)
@@ -182,11 +182,11 @@ AviError AVI_print_error (AviError in_error) {
 
        return in_error;
 }
-
+/*
 void AVI_set_debug (int mode) {
        AVI_DEBUG= mode;
 }
-
+*/
 /*
 int AVI_is_avi (char *name) {
        FILE *fp;
index b58ada878de744f9e4cba46e0d26505a1077e5c9..fa1490620d63f20403eb1dbe614bf0071d6ffdc4 100644 (file)
@@ -352,7 +352,8 @@ int cdf_write_open(CDataFile *cdf, char *filename)
 
        /* fill header */
        header= &cdf->header;
-       strcpy(header->ID, "BCDF");
+       /* strcpy(, "BCDF"); // terminator out of range */
+       header->ID[0]= 'B'; header->ID[1]= 'C'; header->ID[2]= 'D'; header->ID[3]= 'F';
        header->endian= cdf_endian();
        header->version= CDF_VERSION;
        header->subversion= CDF_SUBVERSION;
index e34b1d0a1dd3e0478ceaef48416a7d1c64e32c66..98298950c19d62ce10bccbbb0edd545ec53222e0 100644 (file)
  * since we have to force clearing all Python related data before freeing
  * Blender's library. Still testing, will decide later (Willian). */
 
-//XXX 
-#if 0
-void free_script (Script *script)
-{
-       if (!script) return;
-#ifndef DISABLE_PYTHON
-       BPY_clear_script(script);
-#endif
-}
-#endif
index 15277c438f415090d1999a3561a365f74c5dcb4f..ae20eda5a592cb245fe046dc29a98d816aced254 100644 (file)
@@ -159,7 +159,7 @@ int BLI_gzip(char *from, char *to) {
        
        file = open(from,O_BINARY|O_RDONLY);
        
-       if ( -1 == file )       return -2;
+       if (file < 0)   return -2;
 
        while ( 1 )
        {
index c830e5fc2c8384272232caef014f51957ccfba40..09bca168e6415a2b77c918ddf2fd3fedef9cf005 100644 (file)
@@ -440,7 +440,7 @@ int BLI_filepathsize(const char *path)
 {
        int size, file = open(path, O_BINARY|O_RDONLY);
        
-       if (file <= 0)
+       if (file < 0)
                return -1;
        
        size = BLI_filesize(file);
index fd665f07767460be62f119112837f90249c001f1..ea444b2d0149c1ccb1db971f574ef181ebc208e6 100644 (file)
@@ -230,12 +230,8 @@ void CutEdgeloop(Object *obedit, wmOperator *op, EditMesh *em, int numcuts)
                        nearest = findnearestedge(&vc, &dist);  // returns actual distance in dist
 //                     scrarea_do_windraw(curarea);    // after findnearestedge, backbuf!
                        
-                       sprintf(msg,"Number of Cuts: %d",numcuts);
-                       if(smooth){
-                               sprintf(msg,"%s (S)mooth: on",msg);
-                       } else {
-                               sprintf(msg,"%s (S)mooth: off",msg);
-                       }
+                       sprintf(msg,"Number of Cuts: %d (S)mooth: ",numcuts);
+            strcat(msg, smooth ? "on":"off");
                        
 //                     headerprint(msg);
                        /* Need to figure preview */
index c29214f4633dbba6b544d0cb83e6d478971f1f0e..eccb257dab52d2a56aa77cb0e914240bd2ec1e7b 100644 (file)
@@ -3803,15 +3803,15 @@ int PE_minmax(Scene *scene, float *min, float *max)
 {
        Object *ob= OBACT;
        PTCacheEdit *edit= PE_get_current(scene, ob);
-       ParticleSystem *psys = edit->psys;
+       ParticleSystem *psys;
        ParticleSystemModifierData *psmd = NULL;
        POINT_P; KEY_K;
        float co[3], mat[4][4];
        int ok= 0;
 
        if(!edit) return ok;
-       
-       if(psys)
+
+       if((psys = edit->psys))
                psmd= psys_get_modifier(ob, psys);
        else
                unit_m4(mat);
index ade906ce678d9cb0010f76c5ef82b3d1b8ee9ca3..18ba149d7ed843e98738b53a31cb6e5ff6dccf20 100644 (file)
@@ -298,7 +298,6 @@ static int buttons_context_path_particle(ButsContextPath *path)
 static int buttons_context_path_brush(const bContext *C, ButsContextPath *path)
 {
        Scene *scene;
-       ToolSettings *ts;
        Brush *br= NULL;
        PointerRNA *ptr= &path->ptr[path->len-1];
 
@@ -309,7 +308,6 @@ static int buttons_context_path_brush(const bContext *C, ButsContextPath *path)
        /* if we have a scene, use the toolsettings brushes */
        else if(buttons_context_path_scene(path)) {
                scene= path->ptr[path->len-1].data;
-               ts= scene->toolsettings;
 
                if(scene)
                        br= paint_brush(paint_get_active(scene));
index 8060514accd8ad1f23febd2ea01ff5ddc4a1c132..8f20b53c296175a6ea4fffa5eabfa09927b8cebe 100644 (file)
@@ -402,12 +402,12 @@ void drawaxes(float size, int flag, char drawtype)
                break;
        
        case OB_EMPTY_SPHERE:
-                draw_empty_sphere(size);
-            break;
+               draw_empty_sphere(size);
+               break;
 
        case OB_EMPTY_CONE:
-                draw_empty_cone(size);
-            break;
+               draw_empty_cone(size);
+               break;
 
        case OB_ARROWS:
        default:
@@ -1361,7 +1361,7 @@ static void mesh_foreachScreenEdge__mapFunc(void *userData, int index, float *v0
                        view3d_project_short_noclip(data->vc.ar, v1co, s[1]);
 
                        if (data->clipVerts==2) {
-                if (!(s[0][0]>=0 && s[0][1]>= 0 && s[0][0]<data->vc.ar->winx && s[0][1]<data->vc.ar->winy)) 
+                               if (!(s[0][0]>=0 && s[0][1]>= 0 && s[0][0]<data->vc.ar->winx && s[0][1]<data->vc.ar->winy))
                                        if (!(s[1][0]>=0 && s[1][1]>= 0 && s[1][0]<data->vc.ar->winx && s[1][1]<data->vc.ar->winy)) 
                                                return;
                        }
@@ -2399,7 +2399,7 @@ static void draw_em_measure_stats(View3D *v3d, RegionView3D *rv3d, Object *ob, E
                                }
                        }
                }
-       }    
+       }
        
        if(v3d->zbuf) {
                glEnable(GL_DEPTH_TEST);
@@ -2971,7 +2971,7 @@ static int draw_mesh_object(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                        finalDM = cageDM = editmesh_get_derived_base(ob, em);
                else
                        cageDM = editmesh_get_derived_cage_and_final(scene, ob, em, &finalDM,
-                                                       v3d->customdata_mask);
+                                                                                       v3d->customdata_mask);
 
                if(dt>OB_WIRE) {
                        // no transp in editmode, the fancy draw over goes bad then
@@ -4003,11 +4003,13 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
                                                sprintf(val, " %i", a);
 
                                        if(part->draw&PART_DRAW_NUM && part->draw&PART_DRAW_HEALTH)
-                                               sprintf(val, "%s:", val);
-
-                                       if(part->draw&PART_DRAW_HEALTH && a < totpart && part->phystype==PART_PHYS_BOIDS)
-                                               sprintf(val, "%s %.2f", val, pa_health);
+                                               strcat(val, ":");
 
+                                       if(part->draw&PART_DRAW_HEALTH && a < totpart && part->phystype==PART_PHYS_BOIDS) {
+                                               char tval[8];
+                                               sprintf(tval, " %.2f", pa_health);
+                                               strcat(val, tval);
+                                       }
                                        /* in path drawing state.co is the end point */
                                        view3d_cached_text_draw_add(state.co[0],  state.co[1],  state.co[2], val, 0);
                                }
@@ -4826,7 +4828,7 @@ static void draw_empty_sphere (float size)
 static void draw_empty_cone (float size)
 {
        float cent=0;
-    float radius;
+       float radius;
        GLUquadricObj *qobj = gluNewQuadric(); 
        gluQuadricDrawStyle(qobj, GLU_SILHOUETTE); 
        
@@ -4946,11 +4948,11 @@ static void drawspiral(float *cent, float rad, float tmat[][4], int start)
  */
 static void drawcircle_size(float size)
 {
-    float x, y;
+       float x, y;
        short degrees;
 
        glBegin(GL_LINE_LOOP);
-    
+
        /* coordinates are: cos(degrees*11.25)=x, sin(degrees*11.25)=y, 0.0f=z */
        for (degrees=0; degrees<32; degrees++) {
                x= *(cosval + degrees);
@@ -5824,7 +5826,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                                        float selboxw;
 
                                        cpack(0xffffff);
-                                       set_inverted_drawing(1);                
+                                       set_inverted_drawing(1);
                                        for (i=0; i<(selend-selstart+1); i++) {
                                                SelBox *sb = &(cu->selboxes[i]);
 
@@ -5839,12 +5841,12 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                                                }
                                                glBegin(GL_QUADS);
                                                glVertex3f(sb->x, sb->y, 0.001);
-                                               glVertex3f(sb->x+selboxw, sb->y, 0.001);                                
+                                               glVertex3f(sb->x+selboxw, sb->y, 0.001);
                                                glVertex3f(sb->x+selboxw, sb->y+sb->h, 0.001);
                                                glVertex3f(sb->x, sb->y+sb->h, 0.001);
                                                glEnd();
                                        }
-                                       set_inverted_drawing(0);                        
+                                       set_inverted_drawing(0);
                                }
                        }
                        else if(dt==OB_BOUNDBOX) 
index a680a3bd40d4d550c2b095f01c3f0739d21bd673..be607d7ea778bdaeff65141e1b61bbf56d60d02b 100644 (file)
@@ -829,7 +829,7 @@ static void draw_selected_name(Scene *scene, Object *ob, View3D *v3d)
                                if(kb){
                                        sprintf(shapes, ": %s ", kb->name);             
                                        if(ob->shapeflag == OB_SHAPE_LOCK){
-                                               sprintf(shapes, "%s (Pinned)",shapes);
+                                               strcat(shapes, " (Pinned)");
                                        }
                                }
                        }
index f248e6bb6c43cbe5f1b3db5733eab4368b2845e7..61254944001e3022935bc1eb6596536d03006dc7 100644 (file)
@@ -279,7 +279,7 @@ struct ImBuf *IMB_loadiffname(const char *naam, int flags) {
 
        file = open(naam, O_BINARY|O_RDONLY);
 
-       if (file == -1) return (0);
+       if (file < 0) return (0);
 
        ibuf= IMB_loadifffile(file, flags);
 
@@ -304,7 +304,7 @@ struct ImBuf *IMB_testiffname(char *naam,int flags) {
        flags |= IB_test;
        file = open(naam,O_BINARY|O_RDONLY);
 
-       if (file<=0) return (0);
+       if (file < 0) return (0);
 
        ibuf=IMB_loadifffile(file,flags);
        if (ibuf) {
index c89bc6a632f7fbb9f021643ac01cf50557b868c3..acc3e06448f81ef7a4dedcdf1fe4373b37ed282f 100644 (file)
@@ -296,7 +296,10 @@ short imb_savetarga(struct ImBuf * ibuf, char *name, int flags)
 
        if (ibuf->cmap){
                for (i = 0 ; i<ibuf->maxcol ; i++){
-                       if (fwrite(((uchar *)(ibuf->cmap + i)) + 1,1,3,fildes) != 3) return (0);
+                       if (fwrite(((uchar *)(ibuf->cmap + i)) + 1,1,3,fildes) != 3) {
+                fclose(fildes);
+                return (0);
+            }
                }
        }
        
index 6a94443dd8b114dc909efc1d2ca3f8c26101180a..6ddcb5ff246afc634b803a16a07d7800c15f5102 100644 (file)
@@ -129,7 +129,6 @@ extern "C" {
 //     void BPY_spacescript_do_pywin_draw( struct SpaceScript *sc );
 //     void BPY_spacescript_do_pywin_event( struct SpaceScript *sc,
 //                                          unsigned short event, short val, char ascii );
-//     void BPY_clear_script( struct Script *script );
 //     void BPY_free_finished_script( struct Script *script );
 //     void BPY_scripts_clear_pyobjects( void );
 //
index 303fd84ee60f77107fc4aeb5405e70af03c04115..7acc62b883e4865fce063d11f9678c03c409d7e0 100644 (file)
@@ -30,7 +30,6 @@
 //void BPY_run_python_script() {}
 //void BPY_start_python() {}
 void BPY_call_importloader() {}
-void BPY_clear_script() {}
 //void BPY_free_compiled_text() {}
 void BPY_pyconstraint_eval() {}
 void BPY_pyconstraint_target() {}
index c89811a62e08ed8b807fc534c4a951aa926004eb..05153113a55eb96f9d31431230dbf74da05426b0 100644 (file)
@@ -5200,7 +5200,7 @@ static int load_fluidsimspeedvectors(Render *re, ObjectInstanceRen *obi, float *
        float mat[4][4], winmat[4][4];
        float imat[4][4];
        FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(fsob, eModifierType_Fluidsim);
-       FluidsimSettings *fss = fluidmd->fss;
+       FluidsimSettings *fss;
        float *velarray = NULL;
        
        /* only one step needed */