Fix a bunch of compiler warnings (backported from 'master')

Many warnings were benign, some were false positives, but better
fix a warning than miss an error.

test/fractals.cxx: backported from 1.4
This commit is contained in:
Albrecht Schlosser 2024-03-15 21:26:51 +01:00
parent 25d7ed7e0d
commit 4f787cc1f0
3 changed files with 112 additions and 113 deletions

View File

@ -88,7 +88,7 @@ private:
return(_size);
}
void size(int count) {
if ( count != _size ) {
if ( count > 0 && count != _size ) {
arr = (char*)realloc(arr, count * sizeof(char));
_size = count;
}

View File

@ -95,7 +95,8 @@ static int scroll_x = 0;
*/
Fl_Text_Display::Fl_Text_Display(int X, int Y, int W, int H, const char* l)
: Fl_Group(X, Y, W, H, l) {
int i;
#define VISIBLE_LINES_INIT 1 // allow compiler to remove unused code (PR #582)
mMaxsize = 0;
damage_range1_start = damage_range1_end = -1;
@ -148,11 +149,14 @@ Fl_Text_Display::Fl_Text_Display(int X, int Y, int W, int H, const char* l)
mStyleBuffer = 0;
mStyleTable = 0;
mNStyles = 0;
mNVisibleLines = 1;
mNVisibleLines = VISIBLE_LINES_INIT;
mLineStarts = new int[mNVisibleLines];
mLineStarts[0] = 0;
for (i=1; i<mNVisibleLines; i++)
mLineStarts[i] = -1;
#if VISIBLE_LINES_INIT > 1
{ // Note: this code is unused unless mNVisibleLines is ever initialized > 1
for (int i=1; i<mNVisibleLines; i++) mLineStarts[i] = -1;
}
#endif
mSuppressResync = 0;
mNLinesDeleted = 0;
mModifyingTabDistance = 0;

View File

@ -1,23 +1,21 @@
//
// "$Id$"
//
// Fractal drawing demo for the Fast Light Tool Kit (FLTK).
//
// This is a GLUT demo program, with modifications to
// demonstrate how to add FLTK controls to a GLUT program. The GLUT
// code is unchanged except for the end (search for FLTK to find changes).
//
// Copyright 1998-2016 by Bill Spitzak and others.
// Copyright 1998-2024 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
// http://www.fltk.org/COPYING.php
// https://www.fltk.org/COPYING.php
//
// Please report all bugs and problems on the following page:
// Please see the following page on how to report bugs and issues:
//
// http://www.fltk.org/str.php
// https://www.fltk.org/bugs.php
//
#include <config.h>
@ -79,6 +77,7 @@ typedef enum { NOTALLOWED, MOUNTAIN, TREE, ISLAND, BIGMTN, STEM, LEAF,
MOUNTAIN_MAT, WATER_MAT, LEAF_MAT, TREE_MAT, STEMANDLEAVES,
AXES } DisplayLists;
// Note: MAXLEVEL is the highest level, range is 0..MAXLEVEL
#define MAXLEVEL 8
int Rebuild = 1, /* Rebuild display list in next display? */
@ -133,7 +132,7 @@ void triagnormal(float v1[3], float v2[3], float v3[3], float norm[3])
float xzlength(float v1[3], float v2[3])
{
return sqrt((v1[0] - v2[0])*(v1[0] - v2[0]) +
return sqrtf((v1[0] - v2[0])*(v1[0] - v2[0]) +
(v1[2] - v2[2])*(v1[2] - v2[2]));
}
@ -148,10 +147,10 @@ float xzslope(float v1[3], float v2[3])
/************************ MOUNTAIN STUFF ***********************/
/***************************************************************/
GLfloat DispFactor[MAXLEVEL]; /* Array of what to multiply random number
GLfloat DispFactor[MAXLEVEL + 1]; /* Array of what to multiply random number
by for a given level to get midpoint
displacement */
GLfloat DispBias[MAXLEVEL]; /* Array of what to add to random number
GLfloat DispBias[MAXLEVEL + 1]; /* Array of what to add to random number
before multiplying it by DispFactor */
#define NUMRANDS 191
@ -175,7 +174,7 @@ void InitRandTable(unsigned int seed)
srand48((long) seed);
for (i = 0; i < NUMRANDS; i++)
RandTable[i] = drand48() - 0.5;
RandTable[i] = drand48() - 0.5f;
}
/* calculate midpoint and displace it if required */
@ -235,9 +234,9 @@ void FMR(GLfloat v1[3], GLfloat v2[3], GLfloat v3[3], int level)
void FractalMountain(GLfloat v1[3], GLfloat v2[3], GLfloat v3[3],
int pegged[3])
{
GLfloat lengths[MAXLEVEL];
GLfloat fraction[8] = { 0.3, 0.3, 0.4, 0.2, 0.3, 0.2, 0.4, 0.4 };
GLfloat bias[8] = { 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 };
GLfloat lengths[MAXLEVEL + 1];
GLfloat fraction[8] = { 0.3f, 0.3f, 0.4f, 0.2f, 0.3f, 0.2f, 0.4f, 0.4f };
GLfloat bias[8] = { 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f };
int i;
float avglen = (xzlength(v1, v2) +
xzlength(v2, v3) +
@ -290,7 +289,7 @@ void CreateMountain(void)
*/
void NewMountain(void)
{
InitRandTable(time(NULL));
InitRandTable((unsigned int)time(NULL));
}
/***************************************************************/
@ -313,28 +312,28 @@ void FractalTree(int level, long level_seed)
} else {
glCallList(STEM);
glPushMatrix();
glRotatef(drand48()*180, 0, 1, 0);
glTranslatef(0, 1, 0);
glScalef(0.7, 0.7, 0.7);
glRotatef(drand48()*180.0f, 0.0f, 1.0f, 0.0f);
glTranslatef(0.0f, 1.0f, 0.0f);
glScalef(0.7f, 0.7f, 0.7f);
srand48(level_seed+1);
glPushMatrix();
glRotatef(110 + drand48()*40, 0, 1, 0);
glRotatef(30 + drand48()*20, 0, 0, 1);
glRotatef(110.0f + drand48()*40.0f, 0.0f, 1.0f, 0.0f);
glRotatef( 30.0f + drand48()*20.0f, 0.0f, 0.0f, 1.0f);
FractalTree(level + 1, level_seed+4);
glPopMatrix();
srand48(level_seed+2);
glPushMatrix();
glRotatef(-130 + drand48()*40, 0, 1, 0);
glRotatef(30 + drand48()*20, 0, 0, 1);
glRotatef(-130.0f + drand48()*40.0f, 0.0f, 1.0f, 0.0f);
glRotatef( 30.0f + drand48()*20.0f, 0.0f, 0.0f, 1.0f);
FractalTree(level + 1, level_seed+5);
glPopMatrix();
srand48(level_seed+3);
glPushMatrix();
glRotatef(-20 + drand48()*40, 0, 1, 0);
glRotatef(30 + drand48()*20, 0, 0, 1);
glRotatef(-20.0f + drand48()*40.0f, 0.0f, 1.0f, 0.0f);
glRotatef( 30.0f + drand48()*20.0f, 0.0f, 0.0f, 1.0f);
FractalTree(level + 1, level_seed+6);
glPopMatrix();
@ -352,22 +351,22 @@ void CreateTreeLists(void)
glNewList(STEM, GL_COMPILE);
glPushMatrix();
glRotatef(-90, 1, 0, 0);
glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
gluCylinder(cylquad, 0.1, 0.08, 1, 10, 2 );
glPopMatrix();
glEndList();
glNewList(LEAF, GL_COMPILE); /* I think this was jeff allen's leaf idea */
glBegin(GL_TRIANGLES);
glNormal3f(-0.1, 0, 0.25); /* not normalized */
glVertex3f(0, 0, 0);
glVertex3f(0.25, 0.25, 0.1);
glVertex3f(0, 0.5, 0);
glNormal3f(-0.1f, 0.00f, 0.25f); /* not normalized */
glVertex3f( 0.0f, 0.00f, 0.00f);
glVertex3f(0.25f, 0.25f, 0.10f);
glVertex3f(0.00f, 0.50f, 0.00f);
glNormal3f(0.1, 0, 0.25);
glVertex3f(0, 0, 0);
glVertex3f(0, 0.5, 0);
glVertex3f(-0.25, 0.25, 0.1);
glNormal3f( 0.10f, 0.00f, 0.25f);
glVertex3f( 0.00f, 0.00f, 0.00f);
glVertex3f( 0.00f, 0.50f, 0.00f);
glVertex3f(-0.25f, 0.25f, 0.10f);
glEnd();
glEndList();
@ -377,16 +376,16 @@ void CreateTreeLists(void)
glCallList(STEM);
glCallList(LEAF_MAT);
for(i = 0; i < 3; i++) {
glTranslatef(0, 0.333, 0);
glRotatef(90, 0, 1, 0);
glTranslatef(0.0f, 0.333f, 0.0f);
glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
glPushMatrix();
glRotatef(0, 0, 1, 0);
glRotatef(50, 1, 0, 0);
glRotatef( 0.0f, 0.0f, 1.0f, 0.0f);
glRotatef(50.0f, 1.0f, 0.0f, 0.0f);
glCallList(LEAF);
glPopMatrix();
glPushMatrix();
glRotatef(180, 0, 1, 0);
glRotatef(60, 1, 0, 0);
glRotatef(180.0f, 0.0f, 1.0f, 0.0f);
glRotatef( 60.0f, 1.0f, 0.0f, 0.0f);
glCallList(LEAF);
glPopMatrix();
}
@ -420,7 +419,7 @@ void CreateTree(void)
*/
void NewTree(void)
{
TreeSeed = time(NULL);
TreeSeed = long(time(NULL)); // use time() as random seed
}
/***************************************************************/
@ -429,7 +428,7 @@ void NewTree(void)
void CreateIsland(void)
{
cutoff = .06;
cutoff = .06f;
CreateMountain();
cutoff = -1;
glNewList(ISLAND, GL_COMPILE);
@ -439,39 +438,39 @@ void CreateIsland(void)
glCallList(WATER_MAT);
glBegin(GL_QUADS);
glNormal3f(0, 1, 0);
glVertex3f(10, 0.01, 10);
glVertex3f(10, 0.01, -10);
glVertex3f(-10, 0.01, -10);
glVertex3f(-10, 0.01, 10);
glNormal3f( 0.0f, 1.00f, 0.0f);
glVertex3f( 10.0f, 0.01f, 10.0f);
glVertex3f( 10.0f, 0.01f, -10.0f);
glVertex3f(-10.0f, 0.01f, -10.0f);
glVertex3f(-10.0f, 0.01f, 10.0f);
glEnd();
glPushMatrix();
glTranslatef(0, -0.1, 0);
glTranslatef(0.0f, -0.1f, 0.0f);
glCallList(MOUNTAIN);
glPopMatrix();
glPushMatrix();
glRotatef(135, 0, 1, 0);
glTranslatef(0.2, -0.15, -0.4);
glRotatef(135.0f, 0.0f, 1.0f, 0.0f);
glTranslatef(0.2f, -0.15f, -0.4f);
glCallList(MOUNTAIN);
glPopMatrix();
glPushMatrix();
glRotatef(-60, 0, 1, 0);
glTranslatef(0.7, -0.07, 0.5);
glRotatef(-60.0f, 0.0f, 1.0f, 0.0f);
glTranslatef(0.7f, -0.07f, 0.5f);
glCallList(MOUNTAIN);
glPopMatrix();
glPushMatrix();
glRotatef(-175, 0, 1, 0);
glTranslatef(-0.7, -0.05, -0.5);
glRotatef(-175.0f, 0.0f, 1.0f, 0.0f);
glTranslatef(-0.7f, -0.05f, -0.5f);
glCallList(MOUNTAIN);
glPopMatrix();
glPushMatrix();
glRotatef(165, 0, 1, 0);
glTranslatef(-0.9, -0.12, 0.0);
glRotatef(165.0f, 0.0f, 1.0f, 0.0f);
glTranslatef(-0.9f, -0.12f, 0.0f);
glCallList(MOUNTAIN);
glPopMatrix();
@ -511,21 +510,21 @@ void Create(int fract)
void SetupMaterials(void)
{
GLfloat mtn_ambuse[] = { 0.426, 0.256, 0.108, 1.0 };
GLfloat mtn_specular[] = { 0.394, 0.272, 0.167, 1.0 };
GLfloat mtn_shininess[] = { 10 };
GLfloat mtn_ambuse[] = { 0.426f, 0.256f, 0.108f, 1.0f };
GLfloat mtn_specular[] = { 0.394f, 0.272f, 0.167f, 1.0f };
GLfloat mtn_shininess[] = { 10.0f };
GLfloat water_ambuse[] = { 0.0, 0.1, 0.5, 1.0 };
GLfloat water_specular[] = { 0.0, 0.1, 0.5, 1.0 };
GLfloat water_shininess[] = { 10 };
GLfloat water_ambuse[] = { 0.0f, 0.1f, 0.5f, 1.0f };
GLfloat water_specular[] = { 0.0f, 0.1f, 0.5f, 1.0f };
GLfloat water_shininess[] = { 10.0f };
GLfloat tree_ambuse[] = { 0.4, 0.25, 0.1, 1.0 };
GLfloat tree_specular[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat tree_shininess[] = { 0 };
GLfloat tree_ambuse[] = { 0.4f, 0.25f, 0.1f, 1.0f };
GLfloat tree_specular[] = { 0.0f, 0.00f, 0.0f, 1.0f };
GLfloat tree_shininess[] = { 0.0f };
GLfloat leaf_ambuse[] = { 0.0, 0.8, 0.0, 1.0 };
GLfloat leaf_specular[] = { 0.0, 0.8, 0.0, 1.0 };
GLfloat leaf_shininess[] = { 10 };
GLfloat leaf_ambuse[] = { 0.0f, 0.8f, 0.0f, 1.0f };
GLfloat leaf_specular[] = { 0.0f, 0.8f, 0.0f, 1.0f };
GLfloat leaf_shininess[] = { 10.0f };
glNewList(MOUNTAIN_MAT, GL_COMPILE);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mtn_ambuse);
@ -554,12 +553,12 @@ void SetupMaterials(void)
void myGLInit(void)
{
GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_position[] = { 0.0, 0.3, 0.3, 0.0 };
GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat light_position[] = { 0.0f, 0.3f, 0.3f, 0.0f };
GLfloat lmodel_ambient[] = { 0.4, 0.4, 0.4, 1.0 };
GLfloat lmodel_ambient[] = { 0.4f, 0.4f, 0.4f, 1.0f };
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
@ -639,7 +638,7 @@ void display(void)
glLoadIdentity();
gluOrtho2D(0.0, winwidth, 0.0, winheight);
sprintf(buf, "FPS=%d", fps);
snprintf(buf, sizeof(buf), "FPS=%d", fps);
glColor3f(1.0f, 1.0f, 1.0f);
gl_font(FL_HELVETICA, 12);
gl_draw(buf, 10, 10);
@ -656,7 +655,7 @@ void display(void)
curtime = time(NULL);
if ((curtime - fpstime) >= 2)
{
fps = (fps + fpscount / (curtime - fpstime)) / 2;
fps = (fps + fpscount / int(curtime - fpstime)) / 2;
fpstime = curtime;
fpscount = 0;
}
@ -825,7 +824,3 @@ int main(int argc, char** argv)
return 0;
}
#endif
//
// End of "$Id$".
//