Skip to content

Commit

Permalink
gdft: change strncpy usage to memcpy
Browse files Browse the repository at this point in the history
All the uses of strncpy in here are based on strlen of the input, so
there's no need to run through an str-based func again.  Switch to a
straight memcpy.  Plus this avoids static checkers that blindly choke
on strncpy.  The code was already adding a trailing NUL byte, so that
isn't problematic either.
  • Loading branch information
vapier committed Jun 22, 2018
1 parent e9bf9dd commit 748578f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/gdft.c
Expand Up @@ -576,7 +576,7 @@ fontFetch (char **error, void *key)
gdFree(a);
return "could not alloc full list of fonts";
}
strncpy(a->fontlist, b->fontlist, b_font_list_len);
memcpy(a->fontlist, b->fontlist, b_font_list_len);
a->fontlist[b_font_list_len] = 0;

a->flags = b->flags;
Expand Down Expand Up @@ -1204,7 +1204,7 @@ BGD_DECLARE(char *) gdImageStringFTEx (gdImage * im, int *brect, int fg, const c
gdMutexUnlock(gdFontCacheMutex);
return "could not alloc full list of fonts";
}
strncpy(strex->fontpath, font->fontpath, fontpath_len);
memcpy(strex->fontpath, font->fontpath, fontpath_len);
strex->fontpath[fontpath_len] = 0;
}
}
Expand Down Expand Up @@ -1769,7 +1769,7 @@ static char * font_pattern(char **fontpath, char *fontpattern)
if (*fontpath == NULL) {
return "could not alloc font path";
}
strncpy(*fontpath, (const char *)file, file_len);
memcpy(*fontpath, (const char *)file, file_len);
(*fontpath)[file_len] = 0;
}
FcPatternDestroy(font);
Expand Down Expand Up @@ -1809,7 +1809,7 @@ static char * font_path(char **fontpath, char *name_list)
gdFree(path);
return "could not alloc full list of fonts";
}
strncpy(fontlist, name_list, name_list_len);
memcpy(fontlist, name_list, name_list_len);
fontlist[name_list_len] = 0;

/*
Expand Down

0 comments on commit 748578f

Please sign in to comment.