Thomas Buck 10 лет назад
Родитель
Сommit
e1e5fdf581
12 измененных файлов: 34 добавлений и 26 удалений
  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 Просмотреть файл

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

+ 2
- 2
Makefile Просмотреть файл

@@ -78,8 +78,8 @@ INSTALL_INCLUDE=$(DESTDIR)/usr/include
78 78
 
79 79
 ###############################################################
80 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 83
 WARNINGS+=-Wno-covered-switch-default -Wno-global-constructors
84 84
 WARNINGS+=-Wno-exit-time-destructors -Wno-c++98-compat-pedantic
85 85
 WARNINGS+=-Wno-disabled-macro-expansion -Wno-missing-variable-declarations

+ 2
- 0
include/GLString.h Просмотреть файл

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

+ 1
- 0
include/OpenRaider.h Просмотреть файл

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

+ 1
- 1
include/Quaternion.h Просмотреть файл

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

+ 1
- 0
include/System.h Просмотреть файл

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

+ 1
- 0
include/Texture.h Просмотреть файл

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

+ 3
- 1
include/TombRaider.h Просмотреть файл

@@ -2238,8 +2238,10 @@ private:
2238 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 2245
     void printDebug(const char *methodName, const char *s, ...);
2244 2246
 
2245 2247
 

+ 1
- 0
include/tga.h Просмотреть файл

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

+ 2
- 2
src/OpenRaider.cpp Просмотреть файл

@@ -610,7 +610,7 @@ void OpenRaider::handleConsoleKeyPressEvent(unsigned int key,unsigned int mod)
610 610
                 i = lastCmd[0];
611 611
 
612 612
                 lastCmd[0] = '>';
613
-                mText->SetString(textConsole, lastCmd);
613
+                mText->SetString(textConsole, "%s", lastCmd);
614 614
                 break;
615 615
             case 0:
616 616
                 break;
@@ -849,7 +849,7 @@ void OpenRaider::print(bool dump_stdout, const char *format, ...)
849 849
     // Print to game 'console'
850 850
     if (mText)
851 851
     {
852
-        mText->SetString(textOutput, buffer);
852
+        mText->SetString(textOutput, "%s", buffer);
853 853
     }
854 854
 
855 855
     // Print to stdout

+ 10
- 10
src/Render.cpp Просмотреть файл

@@ -261,8 +261,8 @@ void Render::initTextures(char *textureDir, unsigned int *numLoaded,
261 261
     // String 0: OpenRaider version in lower right corner
262 262
     mString.Scale(1.00);
263 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 267
     if (err)
268 268
     {
@@ -271,8 +271,8 @@ void Render::initTextures(char *textureDir, unsigned int *numLoaded,
271 271
 
272 272
     // String 1: Used for FPS in game text output
273 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 277
     if (err)
278 278
     {
@@ -281,8 +281,8 @@ void Render::initTextures(char *textureDir, unsigned int *numLoaded,
281 281
 
282 282
     // String 2: Used for game console
283 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 287
     if (err)
288 288
     {
@@ -291,8 +291,8 @@ void Render::initTextures(char *textureDir, unsigned int *numLoaded,
291 291
 
292 292
     // String 3: Used for one line map select menu
293 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 297
     if (err)
298 298
     {
@@ -301,8 +301,8 @@ void Render::initTextures(char *textureDir, unsigned int *numLoaded,
301 301
 
302 302
     // String 4: Used for one line in game text output
303 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 307
     if (err)
308 308
     {

+ 9
- 10
src/TombRaider.cpp Просмотреть файл

@@ -544,7 +544,7 @@ int TombRaider::Load(char *filename, void (*percent)(int))
544 544
 
545 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 548
                 usz, sizeof(tr2_textile32_t), _num_textiles);
549 549
 
550 550
         _textile32 = new tr2_textile32_t[_num_textiles];
@@ -594,7 +594,7 @@ int TombRaider::Load(char *filename, void (*percent)(int))
594 594
 
595 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 598
                 usz, sizeof(tr2_textile16_t), _num_textiles);
599 599
 
600 600
         _textile16 = new tr2_textile16_t[_num_textiles];
@@ -4769,7 +4769,7 @@ int TombRaider::Fread(void *buffer, size_t size, size_t count, FILE *f)
4769 4769
         }
4770 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 4773
                     buffer, size, count, f, num_read);
4774 4774
             reset();
4775 4775
             exit(2);
@@ -5122,7 +5122,7 @@ int TombRaider::loadTR5(FILE *f, void (*percent)(int))
5122 5122
 
5123 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 5126
             usz, sizeof(tr2_textile32_t), _num_textiles);
5127 5127
 
5128 5128
     _textile32 = new tr2_textile32_t[_num_textiles];
@@ -5169,7 +5169,7 @@ int TombRaider::loadTR5(FILE *f, void (*percent)(int))
5169 5169
 
5170 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 5173
             usz, sizeof(tr2_textile16_t), _num_textiles);
5174 5174
 
5175 5175
     _textile16 = new tr2_textile16_t[_num_textiles];
@@ -5435,7 +5435,7 @@ int TombRaider::loadTR5(FILE *f, void (*percent)(int))
5435 5435
         // Start 20byte structure ///////////////
5436 5436
         printDebug("LoadTR5", "20byte struct {");
5437 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 5439
                 mRoomsTR5[i].seperator6[0], mRoomsTR5[i].seperator6[1],
5440 5440
                 mRoomsTR5[i].seperator6[2], mRoomsTR5[i].seperator6[3],
5441 5441
                 mRoomsTR5[i].seperator6[4], mRoomsTR5[i].seperator6[5]);
@@ -5468,7 +5468,7 @@ int TombRaider::loadTR5(FILE *f, void (*percent)(int))
5468 5468
         Fread(&mRoomsTR5[i].unknownR6, 4, 1, f);
5469 5469
         printDebug("LoadTR5", "unknownR6 = %i", mRoomsTR5[i].unknownR6);
5470 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 5473
         Fread(&mRoomsTR5[i].seperator9, 4, 1, f);
5474 5474
         printDebug("LoadTR5", "seperator9 CDCDCDCD | 0x0 = 0x%x",
@@ -5483,7 +5483,7 @@ int TombRaider::loadTR5(FILE *f, void (*percent)(int))
5483 5483
         }
5484 5484
 
5485 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 5487
         printDebug("LoadTR5", "}");
5488 5488
 
5489 5489
 
@@ -6218,7 +6218,7 @@ int TombRaider::loadTR5(FILE *f, void (*percent)(int))
6218 6218
 
6219 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 6222
         return -5;
6223 6223
     }
6224 6224
 
@@ -6318,7 +6318,6 @@ int TombRaider::loadTR5(FILE *f, void (*percent)(int))
6318 6318
     return 0;
6319 6319
 }
6320 6320
 
6321
-
6322 6321
 void TombRaider::print(const char *methodName, const char *s, ...)
6323 6322
 {
6324 6323
     va_list args;

Загрузка…
Отмена
Сохранить