]> granicus.if.org Git - libexpat/commitdiff
Rename xmlCharDup to xcsdup and tighten up the code
authorRhodri James <rhodri@kynesim.co.uk>
Mon, 21 Aug 2017 16:53:10 +0000 (17:53 +0100)
committerSebastian Pipping <sebastian@pipping.org>
Tue, 22 Aug 2017 21:14:54 +0000 (23:14 +0200)
expat/xmlwf/xmlwf.c

index ba09c781c42aafc77a8bc9df1f48c7a420c10b0b..d68f35129044abe9a07da0fa3eb4f9f84aba2476 100644 (file)
@@ -286,19 +286,21 @@ processingInstruction(void *userData, const XML_Char *target,
 }
 
 
-static XML_Char *xmlCharDup(const XML_Char *s)
+static XML_Char *xcsdup(const XML_Char *s)
 {
   XML_Char *result;
-  int len = 0;
+  int count = 0;
+  int numBytes;
 
   /* Get the length of the string, including terminator */
-  while (s[len++] != 0) {
+  while (s[count++] != 0) {
     /* Do nothing */
   }
-  result = malloc(len * sizeof(XML_Char));
+  numBytes = count * sizeof(XML_Char);
+  result = malloc(numBytes);
   if (result == NULL)
     return NULL;
-  memcpy(result, s, len * sizeof(XML_Char));
+  memcpy(result, s, numBytes);
   return result;
 }
 
@@ -310,7 +312,7 @@ startDoctypeDecl(void *userData,
                  int has_internal_subset)
 {
   XmlwfUserData *data = (XmlwfUserData *)userData;
-  data->currentDoctypeName = xmlCharDup(doctypeName);
+  data->currentDoctypeName = xcsdup(doctypeName);
 }
 
 static void
@@ -436,14 +438,14 @@ notationDecl(void *userData,
     fprintf(stderr, "Unable to store NOTATION for output\n");
     return; /* Nothing we can really do about this */
   }
-  entry->notationName = xmlCharDup(notationName);
+  entry->notationName = xcsdup(notationName);
   if (entry->notationName == NULL) {
     fprintf(stderr, "Unable to store NOTATION for output\n");
     free(entry);
     return;
   }
   if (systemId != NULL) {
-    entry->systemId = xmlCharDup(systemId);
+    entry->systemId = xcsdup(systemId);
     if (entry->systemId == NULL) {
       fprintf(stderr, "Unable to store NOTATION for output\n");
       free((void *)entry->notationName);
@@ -455,7 +457,7 @@ notationDecl(void *userData,
     entry->systemId = NULL;
   }
   if (publicId != NULL) {
-    entry->publicId = xmlCharDup(publicId);
+    entry->publicId = xcsdup(publicId);
     if (entry->publicId == NULL) {
       fprintf(stderr, "Unable to store NOTATION for output\n");
       free((void *)entry->systemId); /* Safe if it's NULL */