Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Wrap potentially NULL strings to protect solaris
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 1 Mar 2005 07:45:27 +0000 (07:45 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 1 Mar 2005 07:45:27 +0000 (07:45 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@1127 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/xbt/dict_elm.c
testsuite/xbt/dict_usage.c

index cf03ba9..945c517 100644 (file)
@@ -7,6 +7,7 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
+#include "portable.h" /* PRINTF_STR */
 #include "dict_private.h"  /* prototypes of this module */
 
 XBT_LOG_EXTERNAL_CATEGORY(dict);
 #include "dict_private.h"  /* prototypes of this module */
 
 XBT_LOG_EXTERNAL_CATEGORY(dict);
@@ -344,7 +345,7 @@ _xbt_dictelm_child_search(s_xbt_dictelm_t *p_elm,
   CDEBUG6(dict_search, "search child [%.*s] under [%.*s]=%p (len=%lu)",
          key_len, key,
           p_elm ? (p_elm->key_len?p_elm->key_len:6) : 6, 
   CDEBUG6(dict_search, "search child [%.*s] under [%.*s]=%p (len=%lu)",
          key_len, key,
           p_elm ? (p_elm->key_len?p_elm->key_len:6) : 6, 
-         p_elm ? (p_elm->key?p_elm->key:"(NULL)") : "(head)",
+         p_elm ? PRINTF_STR(p_elm->key) : "(head)",
          p_elm,
          (p_elm&&p_elm->sub) ? xbt_dynar_length(p_elm->sub) : 0);
   
          p_elm,
          (p_elm&&p_elm->sub) ? xbt_dynar_length(p_elm->sub) : 0);
   
@@ -399,7 +400,7 @@ _xbt_dictelm_child_search(s_xbt_dictelm_t *p_elm,
   *p_match  = m;
   CDEBUG6(dict_search, "search [%.*s] in [%.*s]=%p => %s",
          key_len, key,
   *p_match  = m;
   CDEBUG6(dict_search, "search [%.*s] in [%.*s]=%p => %s",
          key_len, key,
-          p_elm?(p_elm->key_len?p_elm->key_len:6):6, p_elm?(p_elm->key?p_elm->key:"(null)"):"(head)",
+          p_elm?(p_elm->key_len?p_elm->key_len:6):6, p_elm?PRINTF_STR(p_elm->key):"(head)",
          p_elm,
          ( m == 0 ? "no child have a common prefix" :
            ( m == 1 ? "selected child have exactly this key" :
          p_elm,
          ( m == 0 ? "no child have a common prefix" :
            ( m == 1 ? "selected child have exactly this key" :
index 44af2de..1a9d63f 100644 (file)
@@ -10,6 +10,7 @@
 #include <stdio.h>
 
 #include "gras.h"
 #include <stdio.h>
 
 #include "gras.h"
+#include "portable.h"
 
 XBT_LOG_EXTERNAL_CATEGORY(dict);
 XBT_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test");
 
 XBT_LOG_EXTERNAL_CATEGORY(dict);
 XBT_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test");
@@ -20,11 +21,9 @@ static xbt_error_t search(xbt_dict_t head,const char*key);
 static xbt_error_t debuged_remove(xbt_dict_t head,const char*key);
 static xbt_error_t traverse(xbt_dict_t head);
 
 static xbt_error_t debuged_remove(xbt_dict_t head,const char*key);
 static xbt_error_t traverse(xbt_dict_t head);
 
-#define STRING(str) (str)?:"(null)"
-
 static void print_str(void *str);
 static void print_str(void *str) {
 static void print_str(void *str);
 static void print_str(void *str) {
-  printf("%s",(char*)STRING(str));
+  printf("%s",(char*)PRINTF_STR(str));
 }
 
 static void fill(xbt_dict_t *head) {
 }
 
 static void fill(xbt_dict_t *head) {
@@ -47,7 +46,7 @@ static void debuged_add(xbt_dict_t head,const char*key)
 {
   char *data=xbt_strdup(key);
 
 {
   char *data=xbt_strdup(key);
 
-  printf("   - Add %s\n",STRING(key));
+  printf("   - Add %s\n",PRINTF_STR(key));
   xbt_dict_set(head,key,data,&free);
   if (XBT_LOG_ISENABLED(dict,xbt_log_priority_debug)) {
     xbt_dict_dump(head,(void (*)(void*))&printf);
   xbt_dict_set(head,key,data,&free);
   if (XBT_LOG_ISENABLED(dict,xbt_log_priority_debug)) {
     xbt_dict_dump(head,(void (*)(void*))&printf);
@@ -61,7 +60,7 @@ static xbt_error_t search(xbt_dict_t head,const char*key) {
 
   
   errcode=xbt_dict_get(head,key,&data);
 
   
   errcode=xbt_dict_get(head,key,&data);
-  printf("   - Search %s. Found %s\n",STRING(key),(char*) STRING(data));fflush(stdout);
+  printf("   - Search %s. Found %s\n",PRINTF_STR(key),(char*) PRINTF_STR(data));fflush(stdout);
   if (!data)
      return errcode;
   if (strcmp((char*)data,key)) 
   if (!data)
      return errcode;
   if (strcmp((char*)data,key)) 
@@ -73,7 +72,7 @@ static xbt_error_t debuged_remove(xbt_dict_t head,const char*key)
 {
   xbt_error_t errcode;
 
 {
   xbt_error_t errcode;
 
-  printf("   Remove '%s'\n",STRING(key));fflush(stdout);
+  printf("   Remove '%s'\n",PRINTF_STR(key));fflush(stdout);
   errcode=xbt_dict_remove(head,key);
   /*  xbt_dict_dump(head,(void (*)(void*))&printf); */
   return errcode;
   errcode=xbt_dict_remove(head,key);
   /*  xbt_dict_dump(head,(void (*)(void*))&printf); */
   return errcode;
@@ -86,7 +85,7 @@ static xbt_error_t traverse(xbt_dict_t head) {
   char *data;
 
   xbt_dict_foreach(head,cursor,key,data) {
   char *data;
 
   xbt_dict_foreach(head,cursor,key,data) {
-    printf("   - Seen:  %s->%s\n",STRING(key),STRING(data));
+    printf("   - Seen:  %s->%s\n",PRINTF_STR(key),PRINTF_STR(data));
     xbt_assert2(!data || !strcmp(key,data),
                 "Key(%s) != value(%s). Abording\n",key,data);
   }
     xbt_assert2(!data || !strcmp(key,data),
                 "Key(%s) != value(%s). Abording\n",key,data);
   }
@@ -125,7 +124,7 @@ int main(int argc,char **argv) {
      int found=0;
      
      xbt_dict_foreach(head,cursor,key,data) {
      int found=0;
      
      xbt_dict_foreach(head,cursor,key,data) {
-       printf("   - Seen:  %s->%s\n",STRING(key),STRING(data));fflush(stdout);
+       printf("   - Seen:  %s->%s\n",PRINTF_STR(key),PRINTF_STR(data));fflush(stdout);
        if (!strcmp(key,"null"))
          found = 1;
      }
        if (!strcmp(key,"null"))
          found = 1;
      }