about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-10-02 15:10:58 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-10-02 15:10:58 +0000
commit2dcdf7b8850b6435cd6339f6c77a2e83f52b76f3 (patch)
treee994502a31e93005521a4d058481741fd6b7cf33 /lib
parent78d7ff61d197ed876cc6e0c31611d8ddcf2a1fe1 (diff)
downloadnetpbm-mirror-2dcdf7b8850b6435cd6339f6c77a2e83f52b76f3.tar.gz
netpbm-mirror-2dcdf7b8850b6435cd6339f6c77a2e83f52b76f3.tar.xz
netpbm-mirror-2dcdf7b8850b6435cd6339f6c77a2e83f52b76f3.zip
cleanup
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3372 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib')
-rw-r--r--lib/colorname.c12
-rw-r--r--lib/libpamcolor.c8
-rw-r--r--lib/libpbmfont0.c4
-rw-r--r--lib/libpbmfont1.c4
-rw-r--r--lib/libpbmfont2.c50
-rw-r--r--lib/libpm.c1
-rw-r--r--lib/libppmcolor.c8
-rw-r--r--lib/pbmfont.h4
8 files changed, 49 insertions, 42 deletions
diff --git a/lib/colorname.c b/lib/colorname.c
index 596d8788..9400adf7 100644
--- a/lib/colorname.c
+++ b/lib/colorname.c
@@ -200,10 +200,16 @@ pm_parse_dictionary_namen(char   const colorname[],
 
     fP = pm_openColornameFile(NULL, TRUE);  /* exits if error */
     canoncolor = strdup(colorname);
+
+    if (!canoncolor)
+        pm_error("Failed to allocate memory for %u-byte color name",
+                 (unsigned)strlen(colorname));
+
     pm_canonstr(canoncolor);
-    gotit = FALSE;
-    colorfileExhausted = FALSE;
-    while (!gotit && !colorfileExhausted) {
+
+    for(gotit = FALSE, colorfileExhausted = FALSE;
+        !gotit && !colorfileExhausted; ) {
+
         colorfileEntry = pm_colorget(fP);
         if (colorfileEntry.colorname) {
             pm_canonstr(colorfileEntry.colorname);
diff --git a/lib/libpamcolor.c b/lib/libpamcolor.c
index 49abd063..f9add1a1 100644
--- a/lib/libpamcolor.c
+++ b/lib/libpamcolor.c
@@ -14,10 +14,6 @@
 #define _FILE_OFFSET_BITS 64
 #define _LARGE_FILES
 
-#define _DEFAULT_SOURCE 1  /* New name for SVID & BSD source defines */
-#define _BSD_SOURCE 1      /* Make sure strdup() is in string.h */
-#define _XOPEN_SOURCE 500  /* Make sure strdup() is in string.h */
-
 #include <string.h>
 #include <limits.h>
 #include <math.h>
@@ -415,8 +411,8 @@ pnm_colorname(struct pam * const pamP,
 
     colorname = ppm_colorname(&colorp, pamP->maxval, hexok);
 
-    retval = strdup(colorname);
-    if (retval == NULL)
+    retval = pm_strdup(colorname);
+    if (retval == pm_strsol)
         pm_error("Couldn't get memory for color name string");
 
     return retval;
diff --git a/lib/libpbmfont0.c b/lib/libpbmfont0.c
index add08047..503c7ee7 100644
--- a/lib/libpbmfont0.c
+++ b/lib/libpbmfont0.c
@@ -216,8 +216,8 @@ pbm_destroybdffont2_base(struct font2 * const font2P) {
 
     free(font2P->selector);
 
-    free(font2P->name);
-    free(font2P->charset_string);
+    pm_strfree(font2P->name);
+    pm_strfree(font2P->charset_string);
     free(font2P->glyph);
 
     if (font2P->oldfont !=NULL)
diff --git a/lib/libpbmfont1.c b/lib/libpbmfont1.c
index 2b0993a9..2d269da7 100644
--- a/lib/libpbmfont1.c
+++ b/lib/libpbmfont1.c
@@ -347,9 +347,9 @@ pbm_loadpbmfont2(const char * const filename) {
     retval->load_fn = LOAD_PBMSHEET;
     retval->default_char = (PM_WCHAR) ' ';
     retval->default_char_defined = TRUE;
-    retval->name = strdup("(PBM sheet font has no name)");
+    retval->name = pm_strdup("(PBM sheet font has no name)");
     retval->charset = ISO646_1991_IRV;
-    retval->charset_string = strdup("ASCII");
+    retval->charset_string = pm_strdup("ASCII");
     retval->total_chars = retval->chars = nCharsInFont;
 
     return(retval);
diff --git a/lib/libpbmfont2.c b/lib/libpbmfont2.c
index e7189921..74fcd724 100644
--- a/lib/libpbmfont2.c
+++ b/lib/libpbmfont2.c
@@ -653,39 +653,49 @@ static void
 processBdfFontNameLine(Readline     * const readlineP,
                        struct font2 * const font2P) {
 
-    if (font2P->name != NULL)
+    if (font2P->name)  /* We've already processed a FONT line */
         pm_error("Multiple FONT lines in BDF font file");
+    else {
+        char * buffer;
 
-    font2P->name = malloc (MAXBDFLINE+1);
-    if (font2P->name == NULL)
-        pm_error("No memory for font name");
+        MALLOCARRAY(buffer, MAXBDFLINE+1);
 
-    if (readlineP->wordCt == 1)
-        strcpy(font2P->name, "(no name)");
+        if (!buffer)
+            pm_error("Failed to get memory for %u-character font name buffer",
+                     MAXBDFLINE+1);
 
-    else {
-        unsigned int tokenCt;
+        if (readlineP->wordCt == 1)
+            strcpy(buffer, "(no name)");
+
+        else {
+            unsigned int tokenCt;
 
-        font2P->name[0] ='\0';
+            buffer[0] ='\0';
 
-        for (tokenCt=1;
-             tokenCt < ARRAY_SIZE(readlineP->arg) &&
-                 readlineP->arg[tokenCt] != NULL; ++tokenCt) {
-          strcat(font2P->name, " ");
-          strcat(font2P->name, readlineP->arg[tokenCt]);
+            for (tokenCt=1;
+                 tokenCt < ARRAY_SIZE(readlineP->arg) &&
+                     readlineP->arg[tokenCt] != NULL; ++tokenCt) {
+                strcat(buffer, " ");
+                strcat(buffer, readlineP->arg[tokenCt]);
+            }
         }
+        font2P->name = buffer;
     }
 }
 
 
+
 static void
-loadCharsetString(const char * const registry,
-                  const char * const encoding,
-                  char **      const string) {
+loadCharsetString(const char *  const registry,
+                  const char *  const encoding,
+                  const char ** const charsetStringP) {
 
+    char * dest;
     unsigned int inCt, outCt;
-    char * const dest = malloc (strlen(registry) + strlen(encoding) + 1);
-    if (dest == NULL)
+
+    dest = malloc(strlen(registry) + strlen(encoding) + 1);
+
+    if (!dest)
         pm_error("no memory to load CHARSET_REGISTRY and CHARSET_ENCODING "
                "from BDF file");
 
@@ -703,7 +713,7 @@ loadCharsetString(const char * const registry,
     }
 
     dest[outCt] = '\0';
-    *string = dest;
+    *charsetStringP = dest;
 }
 
 
diff --git a/lib/libpm.c b/lib/libpm.c
index b335debb..21fad88c 100644
--- a/lib/libpm.c
+++ b/lib/libpm.c
@@ -9,7 +9,6 @@
 **************************************************************************/
 
 #define _DEFAULT_SOURCE      /* New name for SVID & BSD source defines */
-#define _BSD_SOURCE          /* Make sure strdup is in string.h */
 #define _XOPEN_SOURCE 500    /* Make sure ftello, fseeko are defined */
 
 #include "netpbm/pm_config.h"
diff --git a/lib/libppmcolor.c b/lib/libppmcolor.c
index 27340d5f..7079482c 100644
--- a/lib/libppmcolor.c
+++ b/lib/libppmcolor.c
@@ -9,10 +9,6 @@
 ** implied warranty.
 */
 
-#define _DEFAULT_SOURCE 1  /* New name for SVID & BSD source defines */
-#define _BSD_SOURCE 1      /* Make sure strdup() is in string.h */
-#define _XOPEN_SOURCE 500  /* Make sure strdup() is in string.h */
-
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
@@ -194,9 +190,9 @@ processColorfileEntry(struct colorfile_entry const ce,
             *errorP = NULL;
         } else {
             ppm_addtocolorhash(cht, &color, *colornameIndexP);
-            colornames[*colornameIndexP] = strdup(ce.colorname);
+            colornames[*colornameIndexP] = pm_strdup(ce.colorname);
             colors[*colornameIndexP] = color;
-            if (colornames[*colornameIndexP] == NULL)
+            if (colornames[*colornameIndexP] == pm_strsol)
                 pm_asprintf(errorP, "Unable to allocate space for color name");
             else {
                 *errorP = NULL;
diff --git a/lib/pbmfont.h b/lib/pbmfont.h
index 57f19ddc..c8b3934b 100644
--- a/lib/pbmfont.h
+++ b/lib/pbmfont.h
@@ -251,7 +251,7 @@ struct font2 {
            FALSE: font file has no DEFAULT_CHAR field.
         */
 
-    char * name;
+    const char * name;
         /* Name of the font.  Available in BDF fonts.
            NULL means no name.
         */
@@ -261,7 +261,7 @@ struct font2 {
            Set by analyzing following charset_string.
         */
 
-    char * charset_string;
+    const char * charset_string;
         /* Charset registry and encoding.
            Available in most BDF fonts between STARPROPERTIES - ENDPROPERTIES.
            NULL means no name.