Skip to contentSkip to conversation

mini-os: make xenbus_read_integer and xenbus_printf take const strings

PATCH In review Samuel Thibault 2 participants 3 messages Aug 26, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mini-os: make xenbus_read_integer and xenbus_printf take const strings

mini-os: make xenbus_read_integer and xenbus_printf take const strings

extras/mini-os/include/xenbus.h +3 -3
diff -r c2472ded5c7c extras/mini-os/include/xenbus.h
@@ -83,12 +83,12 @@ char *xenbus_transaction_end(xenbus_tran
 			     int *retry);
 
 /* Read path and parse it as an integer.  Returns -1 on error. */
-int xenbus_read_integer(char *path);
+int xenbus_read_integer(const char *path);
 
 /* Contraction of snprintf and xenbus_write(path/node). */
 char* xenbus_printf(xenbus_transaction_t xbt,
-                                  char* node, char* path,
-                                  char* fmt, ...);
+                                  const char* node, const char* path,
+                                  const char* fmt, ...);
 
 /* Reset the XenBus system. */
 void fini_xenbus(void);
extras/mini-os/xenbus/xenbus.c +3 -3
diff -r c2472ded5c7c extras/mini-os/xenbus/xenbus.c
@@ -633,7 +633,7 @@ xenbus_transaction_end(xenbus_transactio
     return NULL;
 }
 
-int xenbus_read_integer(char *path)
+int xenbus_read_integer(const char *path)
 {
     char *res, *buf;
     int t;
@@ -650,8 +650,8 @@ int xenbus_read_integer(char *path)
 }
 
 char* xenbus_printf(xenbus_transaction_t xbt,
-                                  char* node, char* path,
-                                  char* fmt, ...)
+                                  const char* node, const char* path,
+                                  const char* fmt, ...)
 {
 #define BUFFER_SIZE 256
     char fullpath[BUFFER_SIZE];
#1 lore raw
Quoted 10 lines · Samuel Thibault

mini-os: make xenbus_read_integer and xenbus_printf take const strings

diff -r c2472ded5c7c extras/mini-os/include/xenbus.h

extras/mini-os/include/xenbus.h +0 -0
@@ -83,12 +83,12 @@ char *xenbus_transaction_end(xenbus_tran
 			     int *retry);
 

extras/mini-os/include/xenbus.h char *xenbus_transaction_end(xenbus_tran · line 91

Quoted 10 lines
extras/mini-os/include/xenbus.h +3 -3
 /* Read path and parse it as an integer.  Returns -1 on error. */
-int xenbus_read_integer(char *path);
+int xenbus_read_integer(const char *path);
 
 /* Contraction of snprintf and xenbus_write(path/node). */
 char* xenbus_printf(xenbus_transaction_t xbt,
-                                  char* node, char* path,
-                                  char* fmt, ...);
+                                  const char* node, const char* path,
+                                  const char* fmt, ...);

If you annotate that declaration with

__attribute__ ((__format__ (printf, 4, 3)))

then gcc will warn you any time a caller gives incorrect args vs format string, which can catch some otherwise hidden bugs.

Regards,
Daniel

Signature · 4 lines
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
#2 lore raw
Quoted 6 lines · Daniel P. Berrange, le Tue 26 Aug 2008 17:34:37 +0100, a écrit :

If you annotate that declaration with

   __attribute__ ((__format__ (printf, 4, 3)))

then gcc will warn you any time a caller gives incorrect args vs format string, which can catch some otherwise hidden bugs.

Indeed, actually all mini-os's *print* functions should have it, IIRC there are a lot of fixes needed to have this compile with -Werror :)

Samuel