Browse Source

Warnings for printf-wrappers

Thomas Buck 11 years ago
parent
commit
e1e5fdf581
12 changed files with 34 additions and 26 deletions
  1. 1
    0
      ChangeLog
  2. 2
    2
      Makefile
  3. 2
    0
      include/GLString.h
  4. 1
    0
      include/OpenRaider.h
  5. 1
    1
      include/Quaternion.h
  6. 1
    0
      include/System.h
  7. 1
    0
      include/Texture.h
  8. 3
    1
      include/TombRaider.h
  9. 1
    0
      include/tga.h
  10. 2
    2
      src/OpenRaider.cpp
  11. 10
    10
      src/Render.cpp
  12. 9
    10
      src/TombRaider.cpp

+ 1
- 0
ChangeLog View File

11
 	  is added to the map list if it validates.
11
 	  is added to the map list if it validates.
12
 	* The menu map list can now be stepped per folder with the
12
 	* The menu map list can now be stepped per folder with the
13
 	  right and left arrows.
13
 	  right and left arrows.
14
+	* Methods wrapping printf-style functions now get compiler warnings
14
 
15
 
15
 	[ 20140216 ]
16
 	[ 20140216 ]
16
 	* Removed the FastCard option. Not necessary on todays hardware?!
17
 	* Removed the FastCard option. Not necessary on todays hardware?!

+ 2
- 2
Makefile View File

78
 
78
 
79
 ###############################################################
79
 ###############################################################
80
 CC=gcc
80
 CC=gcc
81
-WARNINGS=-Weverything -Wno-padded -Wno-packed -Wno-documentation
82
-WARNINGS+=-Wno-documentation-unknown-command -Wno-format-nonliteral
81
+WARNINGS=-Weverything -Wno-padded -Wno-packed
82
+WARNINGS+=-Wno-documentation-unknown-command
83
 WARNINGS+=-Wno-covered-switch-default -Wno-global-constructors
83
 WARNINGS+=-Wno-covered-switch-default -Wno-global-constructors
84
 WARNINGS+=-Wno-exit-time-destructors -Wno-c++98-compat-pedantic
84
 WARNINGS+=-Wno-exit-time-destructors -Wno-c++98-compat-pedantic
85
 WARNINGS+=-Wno-disabled-macro-expansion -Wno-missing-variable-declarations
85
 WARNINGS+=-Wno-disabled-macro-expansion -Wno-missing-variable-declarations

+ 2
- 0
include/GLString.h View File

74
      * \param string valid string id
74
      * \param string valid string id
75
      * \param s format string and args like for printf
75
      * \param s format string and args like for printf
76
      */
76
      */
77
+    __attribute__((format(printf, 3, 4)))
77
     void SetString(unsigned int string, const char *s, ...);
78
     void SetString(unsigned int string, const char *s, ...);
78
 
79
 
79
     /*!
80
     /*!
89
      * \param string valid format string with args like for printf
90
      * \param string valid format string with args like for printf
90
      * \returns 0 on success, -1 on invalid string, -2 on full string list
91
      * \returns 0 on success, -1 on invalid string, -2 on full string list
91
      */
92
      */
93
+    __attribute__((format(printf, 4, 5)))
92
     int glPrintf(int x, int y, const char *string, ...);
94
     int glPrintf(int x, int y, const char *string, ...);
93
 
95
 
94
     /*!
96
     /*!

+ 1
- 0
include/OpenRaider.h View File

130
      * \param dump_stdout if true, also print to stdout
130
      * \param dump_stdout if true, also print to stdout
131
      * \param format printf() style format string
131
      * \param format printf() style format string
132
      */
132
      */
133
+    __attribute__((format(printf, 3, 4)))
133
     void print(bool dump_stdout, const char *format, ...);
134
     void print(bool dump_stdout, const char *format, ...);
134
 
135
 
135
 protected:
136
 protected:

+ 1
- 1
include/Quaternion.h View File

108
 
108
 
109
     /*!
109
     /*!
110
      * \brief Inverse this quaternion
110
      * \brief Inverse this quaternion
111
-     * \brief Returns inverse of this quaternion
111
+     * \returns inverse of this quaternion
112
      */
112
      */
113
     Quaternion inverse();
113
     Quaternion inverse();
114
 
114
 

+ 1
- 0
include/System.h View File

70
      * \param string Format string like for printf
70
      * \param string Format string like for printf
71
      * \returns string in a buffer
71
      * \returns string in a buffer
72
      */
72
      */
73
+    __attribute__((format(printf, 1, 2)))
73
     static char *bufferString(const char *string, ...);
74
     static char *bufferString(const char *string, ...);
74
 
75
 
75
     /*!
76
     /*!

+ 1
- 0
include/Texture.h View File

249
 
249
 
250
 // Experimental testing
250
 // Experimental testing
251
 
251
 
252
+__attribute__((format(printf, 3, 4)))
252
 void bufferedPrintf(char *string, unsigned int len, char *s, ...);
253
 void bufferedPrintf(char *string, unsigned int len, char *s, ...);
253
 
254
 
254
 void glPrint3d(float x, float y, float z,
255
 void glPrint3d(float x, float y, float z,

+ 3
- 1
include/TombRaider.h View File

2238
      * Mongoose - Created
2238
      * Mongoose - Created
2239
      ------------------------------------------------------*/
2239
      ------------------------------------------------------*/
2240
 
2240
 
2241
-    void print(const char *methodName, const char *s, ...);
2241
+__attribute__((format(printf, 3, 4)))
2242
+    void print(const char *methodName, const char *s, ...) ;
2242
 
2243
 
2244
+__attribute__((format(printf, 3, 4)))
2243
     void printDebug(const char *methodName, const char *s, ...);
2245
     void printDebug(const char *methodName, const char *s, ...);
2244
 
2246
 
2245
 
2247
 

+ 1
- 0
include/tga.h View File

83
  * \param s format string for file path/name
83
  * \param s format string for file path/name
84
  * \returns 0 on success, else error condition
84
  * \returns 0 on success, else error condition
85
  */
85
  */
86
+__attribute__((format(printf, 5, 6)))
86
 int tga_save_filename(unsigned char *image,
87
 int tga_save_filename(unsigned char *image,
87
         unsigned int width, unsigned int height,
88
         unsigned int width, unsigned int height,
88
         char type,
89
         char type,

+ 2
- 2
src/OpenRaider.cpp View File

610
                 i = lastCmd[0];
610
                 i = lastCmd[0];
611
 
611
 
612
                 lastCmd[0] = '>';
612
                 lastCmd[0] = '>';
613
-                mText->SetString(textConsole, lastCmd);
613
+                mText->SetString(textConsole, "%s", lastCmd);
614
                 break;
614
                 break;
615
             case 0:
615
             case 0:
616
                 break;
616
                 break;
849
     // Print to game 'console'
849
     // Print to game 'console'
850
     if (mText)
850
     if (mText)
851
     {
851
     {
852
-        mText->SetString(textOutput, buffer);
852
+        mText->SetString(textOutput, "%s", buffer);
853
     }
853
     }
854
 
854
 
855
     // Print to stdout
855
     // Print to stdout

+ 10
- 10
src/Render.cpp View File

261
     // String 0: OpenRaider version in lower right corner
261
     // String 0: OpenRaider version in lower right corner
262
     mString.Scale(1.00);
262
     mString.Scale(1.00);
263
     err = mString.glPrintf(mWidth - 15 * strlen(VERSION),
263
     err = mString.glPrintf(mWidth - 15 * strlen(VERSION),
264
-            mHeight-35, VERSION);
265
-    mString.SetString(0, VERSION);
264
+            mHeight-35, "%s", VERSION);
265
+    mString.SetString(0, "%s", VERSION);
266
 
266
 
267
     if (err)
267
     if (err)
268
     {
268
     {
271
 
271
 
272
     // String 1: Used for FPS in game text output
272
     // String 1: Used for FPS in game text output
273
     mString.Scale(0.75);
273
     mString.Scale(0.75);
274
-    err = mString.glPrintf(8, mHeight - 25, "                ");
275
-    mString.SetString(1, "                ");
274
+    err = mString.glPrintf(8, mHeight - 25, "%s", "                ");
275
+    mString.SetString(1, "%s", "                ");
276
 
276
 
277
     if (err)
277
     if (err)
278
     {
278
     {
281
 
281
 
282
     // String 2: Used for game console
282
     // String 2: Used for game console
283
     mString.Scale(1.0);
283
     mString.Scale(1.0);
284
-    err = mString.glPrintf(8, 25, console);
285
-    mString.SetString(2, console);
284
+    err = mString.glPrintf(8, 25, "%s", console);
285
+    mString.SetString(2, "%s", console);
286
 
286
 
287
     if (err)
287
     if (err)
288
     {
288
     {
291
 
291
 
292
     // String 3: Used for one line map select menu
292
     // String 3: Used for one line map select menu
293
     mString.Scale(1.75);
293
     mString.Scale(1.75);
294
-    err = mString.glPrintf(mWidth/2-235, mHeight/2-24, menu);
295
-    mString.SetString(3, menu);
294
+    err = mString.glPrintf(mWidth/2-235, mHeight/2-24, "%s", menu);
295
+    mString.SetString(3, "%s", menu);
296
 
296
 
297
     if (err)
297
     if (err)
298
     {
298
     {
301
 
301
 
302
     // String 4: Used for one line in game text output
302
     // String 4: Used for one line in game text output
303
     mString.Scale(1.0);
303
     mString.Scale(1.0);
304
-    err = mString.glPrintf(8, 55, "                    ");
305
-    mString.SetString(4, "                    ");
304
+    err = mString.glPrintf(8, 55, "%s", "                    ");
305
+    mString.SetString(4, "%s", "                    ");
306
 
306
 
307
     if (err)
307
     if (err)
308
     {
308
     {

+ 9
- 10
src/TombRaider.cpp View File

544
 
544
 
545
         _num_textiles = usz / sizeof(tr2_textile32_t);
545
         _num_textiles = usz / sizeof(tr2_textile32_t);
546
 
546
 
547
-        printDebug("LoadTR4", "_num_textiles = %i/%i = %i",
547
+        printDebug("LoadTR4", "_num_textiles = %i/%lu = %i",
548
                 usz, sizeof(tr2_textile32_t), _num_textiles);
548
                 usz, sizeof(tr2_textile32_t), _num_textiles);
549
 
549
 
550
         _textile32 = new tr2_textile32_t[_num_textiles];
550
         _textile32 = new tr2_textile32_t[_num_textiles];
594
 
594
 
595
         _num_textiles = usz / sizeof(tr2_textile16_t);
595
         _num_textiles = usz / sizeof(tr2_textile16_t);
596
 
596
 
597
-        printDebug("Load", "TR4 _num_textiles = %i/%i = %i",
597
+        printDebug("Load", "TR4 _num_textiles = %i/%lu = %i",
598
                 usz, sizeof(tr2_textile16_t), _num_textiles);
598
                 usz, sizeof(tr2_textile16_t), _num_textiles);
599
 
599
 
600
         _textile16 = new tr2_textile16_t[_num_textiles];
600
         _textile16 = new tr2_textile16_t[_num_textiles];
4769
         }
4769
         }
4770
         else
4770
         else
4771
         {
4771
         {
4772
-            print("Fread(%p, %d, %d, %p)", "ERROR: Returned %d bytes too far",
4772
+            print("Fread", "(%p, %lu, %lu, %p) ERROR: Returned %d bytes too far",
4773
                     buffer, size, count, f, num_read);
4773
                     buffer, size, count, f, num_read);
4774
             reset();
4774
             reset();
4775
             exit(2);
4775
             exit(2);
5122
 
5122
 
5123
     _num_textiles = usz / sizeof(tr2_textile32_t);
5123
     _num_textiles = usz / sizeof(tr2_textile32_t);
5124
 
5124
 
5125
-    printDebug("LoadTR5", "_num_textiles = %i/%i = %i",
5125
+    printDebug("LoadTR5", "_num_textiles = %i/%lu = %i",
5126
             usz, sizeof(tr2_textile32_t), _num_textiles);
5126
             usz, sizeof(tr2_textile32_t), _num_textiles);
5127
 
5127
 
5128
     _textile32 = new tr2_textile32_t[_num_textiles];
5128
     _textile32 = new tr2_textile32_t[_num_textiles];
5169
 
5169
 
5170
     _num_textiles = usz / sizeof(tr2_textile16_t);
5170
     _num_textiles = usz / sizeof(tr2_textile16_t);
5171
 
5171
 
5172
-    printDebug("LoadTR5", "_num_textiles = %i/%i = %i",
5172
+    printDebug("LoadTR5", "_num_textiles = %i/%lu = %i",
5173
             usz, sizeof(tr2_textile16_t), _num_textiles);
5173
             usz, sizeof(tr2_textile16_t), _num_textiles);
5174
 
5174
 
5175
     _textile16 = new tr2_textile16_t[_num_textiles];
5175
     _textile16 = new tr2_textile16_t[_num_textiles];
5435
         // Start 20byte structure ///////////////
5435
         // Start 20byte structure ///////////////
5436
         printDebug("LoadTR5", "20byte struct {");
5436
         printDebug("LoadTR5", "20byte struct {");
5437
         Fread(mRoomsTR5[i].seperator6, 6, 1, f);
5437
         Fread(mRoomsTR5[i].seperator6, 6, 1, f);
5438
-        printDebug("LoadTR5", "6 bytes 0xFF = 0x%x%x%x%x%x",
5438
+        printDebug("LoadTR5", "6 bytes 0xFF = 0x%x%x%x%x%x%x",
5439
                 mRoomsTR5[i].seperator6[0], mRoomsTR5[i].seperator6[1],
5439
                 mRoomsTR5[i].seperator6[0], mRoomsTR5[i].seperator6[1],
5440
                 mRoomsTR5[i].seperator6[2], mRoomsTR5[i].seperator6[3],
5440
                 mRoomsTR5[i].seperator6[2], mRoomsTR5[i].seperator6[3],
5441
                 mRoomsTR5[i].seperator6[4], mRoomsTR5[i].seperator6[5]);
5441
                 mRoomsTR5[i].seperator6[4], mRoomsTR5[i].seperator6[5]);
5468
         Fread(&mRoomsTR5[i].unknownR6, 4, 1, f);
5468
         Fread(&mRoomsTR5[i].unknownR6, 4, 1, f);
5469
         printDebug("LoadTR5", "unknownR6 = %i", mRoomsTR5[i].unknownR6);
5469
         printDebug("LoadTR5", "unknownR6 = %i", mRoomsTR5[i].unknownR6);
5470
         Fread(&mRoomsTR5[i].roomX, 4, 1, f);
5470
         Fread(&mRoomsTR5[i].roomX, 4, 1, f);
5471
-        printDebug("LoadTR5", "roomX = %i", mRoomsTR5[i].roomX);
5471
+        printDebug("LoadTR5", "roomX = %f", mRoomsTR5[i].roomX);
5472
 
5472
 
5473
         Fread(&mRoomsTR5[i].seperator9, 4, 1, f);
5473
         Fread(&mRoomsTR5[i].seperator9, 4, 1, f);
5474
         printDebug("LoadTR5", "seperator9 CDCDCDCD | 0x0 = 0x%x",
5474
         printDebug("LoadTR5", "seperator9 CDCDCDCD | 0x0 = 0x%x",
5483
         }
5483
         }
5484
 
5484
 
5485
         Fread(&mRoomsTR5[i].roomZ, 4, 1, f);
5485
         Fread(&mRoomsTR5[i].roomZ, 4, 1, f);
5486
-        printDebug("LoadTR5", "roomZ = %i", mRoomsTR5[i].roomZ);
5486
+        printDebug("LoadTR5", "roomZ = %f", mRoomsTR5[i].roomZ);
5487
         printDebug("LoadTR5", "}");
5487
         printDebug("LoadTR5", "}");
5488
 
5488
 
5489
 
5489
 
6218
 
6218
 
6219
     if (u != 0xcdcdcdcd)
6219
     if (u != 0xcdcdcdcd)
6220
     {
6220
     {
6221
-        print("LoadTR5", "Check 0xCDCDCDCD != 0x%X @ %u", u, ftell(f));
6221
+        print("LoadTR5", "Check 0xCDCDCDCD != 0x%X @ %ld", u, ftell(f));
6222
         return -5;
6222
         return -5;
6223
     }
6223
     }
6224
 
6224
 
6318
     return 0;
6318
     return 0;
6319
 }
6319
 }
6320
 
6320
 
6321
-
6322
 void TombRaider::print(const char *methodName, const char *s, ...)
6321
 void TombRaider::print(const char *methodName, const char *s, ...)
6323
 {
6322
 {
6324
     va_list args;
6323
     va_list args;

Loading…
Cancel
Save