Fixes for const correctness.
authorPeter Verthez <Peter.Verthez@advalvas.be>
Tue, 17 Sep 2002 15:50:18 +0000 (15:50 +0000)
committerPeter Verthez <Peter.Verthez@advalvas.be>
Tue, 17 Sep 2002 15:50:18 +0000 (15:50 +0000)
gedcom/compat.c

index c566d8e9ab8c77742fcd153705ba377c9ac423dd..3b725483ba8b684798f5d896a1c02d0c70874ac5 100644 (file)
@@ -168,15 +168,24 @@ int compat_generate_char(Gedcom_ctxt parent)
 {
   struct tag_struct ts;
   Gedcom_ctxt self1;
+  char* charset;
   
   /* first generate "1 CHAR <DEFAULT_CHAR>" */
   ts.string = "CHAR";
   ts.value  = TAG_CHAR;
-  self1 = start_element(ELT_HEAD_CHAR, parent, 1, ts, (char*)default_charset,
-                       GEDCOM_MAKE_STRING(val1, (char*)default_charset));
-  
-  /* close "1 CHAR" */
-  end_element(ELT_HEAD_CHAR, parent, self1, NULL);
+
+  /* Must strdup, because default_charset is const char */
+  charset   = strdup(default_charset);
+  if (! charset)
+    MEMORY_ERROR;
+  else {
+    self1 = start_element(ELT_HEAD_CHAR, parent, 1, ts, charset,
+                         GEDCOM_MAKE_STRING(val1, charset));
+    free(charset);
+    
+    /* close "1 CHAR" */
+    end_element(ELT_HEAD_CHAR, parent, self1, NULL);
+  }
   if (open_conv_to_internal(default_charset) == 0)
     return 1;
   else