Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[xsrc/trunk]: xsrc/local/programs/bdfload do not rely on every STARTCHAR/ENDC...
details: https://anonhg.NetBSD.org/xsrc/rev/21ce2a040212
branches: trunk
changeset: 7204:21ce2a040212
user: macallan <macallan%NetBSD.org@localhost>
date: Tue Oct 25 12:55:04 2022 +0000
description:
do not rely on every STARTCHAR/ENDCHAR sequence starting with ENCODING - the
standard doesn't specify in which order each glyph's properties are listed
diffstat:
local/programs/bdfload/bdfload.c | 19 ++++++++++++++-----
1 files changed, 14 insertions(+), 5 deletions(-)
diffs (68 lines):
diff -r 98ef08830d09 -r 21ce2a040212 local/programs/bdfload/bdfload.c
--- a/local/programs/bdfload/bdfload.c Tue Oct 18 07:35:57 2022 +0000
+++ b/local/programs/bdfload/bdfload.c Tue Oct 25 12:55:04 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bdfload.c,v 1.16 2022/09/27 18:29:08 christos Exp $ */
+/* $NetBSD: bdfload.c,v 1.17 2022/10/25 12:55:04 macallan Exp $ */
/*
* Copyright (c) 2018 Michael Lorenz
@@ -232,7 +232,7 @@
void
interpret(FILE *foo)
{
- char line[128], *arg, name[64] = "foo", *buffer;
+ char line[128], *arg, name[64] = "foo", *buffer, *cbitmap;
int buflen = -1;
int in_char = 0, current = -1, stride = 0, charsize = 0;
int width, height, x, y, num;
@@ -288,21 +288,30 @@
"no fonts wider than 16 work for now\n");
}
charsize = height * stride;
- buflen = 256 * charsize;
+ buflen = 257 * charsize;
buffer = calloc(1, buflen);
if (buffer == NULL) {
err(EXIT_FAILURE,
"failed to allocate %dKB for glyphs\n",
buflen);
}
+ cbitmap = buffer + 256 * charsize;
} else if (strcmp(line, "CHARS") == 0) {
if (sscanf(arg, "%d", &num) == 1)
if (verbose)
printf("number of characters: %d\n", num);
} else if (strcmp(line, "STARTCHAR") == 0) {
in_char = 1;
+ if (charsize <= 1) err(EXIT_FAILURE,
+ "syntax error - no valid FONTBOUNDINGBOX\n");
+ memset(cbitmap, 0, charsize);
} else if (strcmp(line, "ENDCHAR") == 0) {
in_char = 0;
+ /* only commit the glyph if it's in range */
+ if ((current >= 0) && (current < 256)) {
+ memcpy(&buffer[charsize * current],
+ cbitmap, charsize);
+ }
current = -1;
} else if (strcmp(line, "ENCODING") == 0) {
if (sscanf(arg, "%d", ¤t) == 1) {
@@ -329,7 +338,7 @@
} else if (strcmp(line, "BITMAP") == 0) {
int i, j, k, l;
char num[32];
- char *gptr = &buffer[charsize * current];
+ char *gptr = cbitmap;
char *bptr = gptr + top;
uint16_t *bptr16 = (uint16_t *)gptr;
bptr16 += top;
@@ -351,7 +360,7 @@
}
}
if (dump) {
- gptr = &buffer[charsize * current];
+ gptr = cbitmap;
for (i = 0; i < height; i++) {
dump_line(gptr, stride);
gptr += stride;
Home |
Main Index |
Thread Index |
Old Index