Complete.Org: Mailing Lists: Archives: freeciv-dev: April 1999:
[Freeciv-Dev] patch: checking printf-like functions args
Home

[Freeciv-Dev] patch: checking printf-like functions args

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] patch: checking printf-like functions args
From: David Pfitzner <dwp@xxxxxxxxxxxxxx>
Date: Sat, 24 Apr 1999 15:20:32 +1000 (EST)

This is a revised version of an old patch to use gcc's __attribute__ 
keyword to check variadic parameters to printf-like functions.
The way this patch does it should be entirely safe for other 
compilers.

-- David
diff -N -u -r --exclude-from exclude fc-adv/common/Makefile.am 
freeciv-mod/common/Makefile.am
--- fc-adv/common/Makefile.am   Thu Apr 22 23:36:58 1999
+++ freeciv-mod/common/Makefile.am      Sat Apr 24 13:13:38 1999
@@ -5,6 +5,7 @@
 INCLUDES =
 
 libcivcommon_a_SOURCES = \
+               attribute.h     \
                capability.c    \
                capability.h    \
                city.c          \
diff -N -u -r --exclude-from exclude fc-adv/common/Makefile.in 
freeciv-mod/common/Makefile.in
--- fc-adv/common/Makefile.in   Thu Apr 22 23:36:58 1999
+++ freeciv-mod/common/Makefile.in      Sat Apr 24 13:19:23 1999
@@ -85,6 +85,7 @@
 INCLUDES =
 
 libcivcommon_a_SOURCES = \
+               attribute.h     \
                capability.c    \
                capability.h    \
                city.c          \
diff -N -u -r --exclude-from exclude fc-adv/common/attribute.h 
freeciv-mod/common/attribute.h
--- fc-adv/common/attribute.h   Thu Jan  1 10:00:00 1970
+++ freeciv-mod/common/attribute.h      Sat Apr 24 13:15:02 1999
@@ -0,0 +1,29 @@
+/********************************************************************** 
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+#ifndef FC__ATTRIBUTE_H
+#define FC__ATTRIBUTE_H
+
+/* Want to use GCC's __attribute__ keyword to check variadic
+ * parameters to printf-like functions, without upsetting other
+ * compilers: put any required defines magic here.
+ * If other compilers have something equivalent, could also
+ * work that out here.   Should this use configure stuff somehow?
+ * --dwp
+ */
+#if defined(__GNUC__)
+#define fc__attribute(x)  __attribute__(x)
+#else
+#define fc__attribute(x)
+#endif
+
+#endif  /* FC__ATTRIBUTE_H */
diff -N -u -r --exclude-from exclude fc-adv/common/log.h 
freeciv-mod/common/log.h
--- fc-adv/common/log.h Thu Apr 22 23:36:58 1999
+++ freeciv-mod/common/log.h    Sat Apr 24 13:16:34 1999
@@ -13,12 +13,15 @@
 #ifndef __LOG_
 #define __LOG_
 
+#include "attribute.h"
+
 #define LOG_FATAL  0
 #define LOG_NORMAL 1
 #define LOG_DEBUG  2
 
 void log_init(char *filename);
-int freelog(int level, char *message, ...);
+int freelog(int level, char *message, ...)
+            fc__attribute((format (printf, 2, 3)));
 void log_set_level(int level);
 void log_kill(void);
 
diff -N -u -r --exclude-from exclude fc-adv/server/plrhand.h 
freeciv-mod/server/plrhand.h
--- fc-adv/server/plrhand.h     Thu Apr 22 23:36:58 1999
+++ freeciv-mod/server/plrhand.h        Sat Apr 24 13:16:29 1999
@@ -13,6 +13,8 @@
 #ifndef __PLRHAND_H
 #define __PLRHAND_H
 
+#include "attribute.h"
+
 struct player;
 struct packet_player_request;
 struct section_file;
@@ -30,9 +32,13 @@
 void send_player_info(struct player *src, struct player *dest);
 
 void page_player(struct player *pplayer, char *headline, char *lines);
-void page_player_generic(struct player *pplayer, char *headline, char *lines, 
int event);
-void notify_player(struct player *pplayer, char *format, ...);
-void notify_player_ex(struct player *pplayer, int x, int y, int event, char 
*format, ...);
+void page_player_generic(struct player *pplayer, char *headline,
+                        char *lines, int event);
+void notify_player(struct player *pplayer, char *format, ...)
+                   fc__attribute((format (printf, 2, 3)));
+void notify_player_ex(struct player *pplayer, int x, int y,
+                     int event, char *format, ...)
+                      fc__attribute((format (printf, 5, 6)));
 void handle_player_government(struct player *pplayer,
                             struct packet_player_request *preq);
 void handle_player_research(struct player *pplayer,
diff -N -u -r --exclude-from exclude fc-adv/server/registry.h 
freeciv-mod/server/registry.h
--- fc-adv/server/registry.h    Thu Apr 22 23:36:58 1999
+++ freeciv-mod/server/registry.h       Sat Apr 24 13:18:52 1999
@@ -14,6 +14,7 @@
 #define __REGISTRY_H
 
 #include "genlist.h"
+#include "attribute.h"
 
 struct hash_data;
 
@@ -38,11 +39,12 @@
 };
 
 void secfile_insert_int(struct section_file *my_section_file, 
-                       int val, char *path, ...);
-
+                       int val, char *path, ...)
+                        fc__attribute((format (printf, 3, 4)));
+     
 void secfile_insert_str(struct section_file *my_section_file, 
-                       char *sval, char *path, ...);
-
+                       char *sval, char *path, ...)
+                        fc__attribute((format (printf, 3, 4)));
 
 int section_file_load(struct section_file *my_section_file, char *filename);
 int section_file_save(struct section_file *my_section_file, char *filename);
@@ -52,26 +54,34 @@
 void section_file_check_unused(struct section_file *file, char *filename);
 
 int secfile_lookup_int(struct section_file *my_section_file, 
-                      char *path, ...);
+                      char *path, ...)
+                       fc__attribute((format (printf, 2, 3)));
 
 char *secfile_lookup_str(struct section_file *my_section_file, 
-                        char *path, ...);
+                        char *path, ...)
+                         fc__attribute((format (printf, 2, 3)));
 
 int secfile_lookup_vec_dimen(struct section_file *my_section_file, 
-                            char *path, ...);
+                            char *path, ...)
+                             fc__attribute((format (printf, 2, 3)));
 int *secfile_lookup_int_vec(struct section_file *my_section_file,
-                           int *dimen, char *path, ...);
+                           int *dimen, char *path, ...)
+                            fc__attribute((format (printf, 3, 4)));
 char **secfile_lookup_str_vec(struct section_file *my_section_file,
-                             int *dimen, char *path, ...);
+                             int *dimen, char *path, ...)
+                              fc__attribute((format (printf, 3, 4)));
 
 int secfile_lookup_int_default(struct section_file *my_section_file,
-                               int def, char *path, ...);
+                               int def, char *path, ...)
+                               fc__attribute((format (printf, 3, 4)));
 
 char *secfile_lookup_str_default(struct section_file *my_section_file, 
-                                 char *def, char *path, ...);
+                                 char *def, char *path, ...)
+                                 fc__attribute((format (printf, 3, 4)));
 
 int section_file_lookup(struct section_file *my_section_file, 
-                       char *path, ...);
+                       char *path, ...)
+                        fc__attribute((format (printf, 2, 3)));
 
 struct section_entry *section_file_lookup_internal(struct section_file 
                                                   *my_section_file,  

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] patch: checking printf-like functions args, David Pfitzner <=