Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[xsrc/trunk]: xsrc/local/programs/ttf2wsfont Fix minor problems detected by G...
details: https://anonhg.NetBSD.org/xsrc/rev/6d7782df15ec
branches: trunk
changeset: 10494:6d7782df15ec
user: rin <rin%NetBSD.org@localhost>
date: Mon Jun 08 15:01:59 2020 +0000
description:
Fix minor problems detected by GCC9 -Wstringop-truncation.
diffstat:
local/programs/ttf2wsfont/main.c | 17 +++++++++--------
1 files changed, 9 insertions(+), 8 deletions(-)
diffs (53 lines):
diff -r 9ede7e1ec2f6 -r 6d7782df15ec local/programs/ttf2wsfont/main.c
--- a/local/programs/ttf2wsfont/main.c Fri Apr 10 16:49:36 2020 +0000
+++ b/local/programs/ttf2wsfont/main.c Mon Jun 08 15:01:59 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.3 2017/06/23 02:15:07 macallan Exp $ */
+/* $NetBSD: main.c,v 1.4 2020/06/08 15:01:59 rin Exp $ */
/*
* Copyright (c) 2011 Michael Lorenz
@@ -76,7 +76,7 @@
int width, datalen, didx, i, start, end, out;
FILE *output;
uint8_t *fontdata;
- char fontname[128], filename[128];
+ char fontname[128], filename[sizeof(fontname) + 4 /* .wsf */];
if (argc != 3) {
printf("usage: ttf2wsfont some_font.ttf height\n");
@@ -141,12 +141,13 @@
}
/* now output as a header file */
- snprintf(fontname, 128, "%s_%dx%d", face->family_name, width, cell_height);
+ snprintf(fontname, sizeof(fontname), "%s_%dx%d", face->family_name,
+ width, cell_height);
for (i = 0; i < strlen(fontname); i++) {
if (isblank((int)fontname[i]))
fontname[i]='_';
}
- snprintf(filename, 128, "%s.h", fontname);
+ snprintf(filename, sizeof(filename), "%s.h", fontname);
if ((output = fopen(filename, "w")) == NULL) {
fprintf(stderr, "Can't open output file %s\n", filename);
return -1;
@@ -185,14 +186,14 @@
fprintf(output, "};\n");
fclose(output);
/* dump as binary */
- snprintf(filename, 128, "%s.wsf", fontname);
+ snprintf(filename, sizeof(filename), "%s.wsf", fontname);
if ((out = open(filename, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE)) > 0) {
char nbuf[64];
uint32_t foo;
write(out, "WSFT", 4);
- memset(nbuf, 0, 64);
- strncpy(nbuf, face->family_name, 64);
- write(out, nbuf, 64);
+ memset(nbuf, 0, sizeof(nbuf));
+ strlcpy(nbuf, face->family_name, sizeof(nbuf));
+ write(out, nbuf, sizeof(nbuf));
/* firstchar */
foo = htole32(32);
write(out, &foo, 4);
Home |
Main Index |
Thread Index |
Old Index