ifix segmentation fault on non-ASCII glyphs - ploot - simple plotting tools Err bitreich.org 70
hgit clone git://bitreich.org/ploot git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/ploot URL:git://bitreich.org/ploot git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/ploot bitreich.org 70
1Log /scm/ploot/log.gph bitreich.org 70
1Files /scm/ploot/files.gph bitreich.org 70
1Refs /scm/ploot/refs.gph bitreich.org 70
1Tags /scm/ploot/tag bitreich.org 70
1README /scm/ploot/file/README.md.gph bitreich.org 70
1LICENSE /scm/ploot/file/LICENSE.gph bitreich.org 70
i--- Err bitreich.org 70
1commit c3fcef87d156b02a9ad8ca7cd47fee4a826534f4 /scm/ploot/commit/c3fcef87d156b02a9ad8ca7cd47fee4a826534f4.gph bitreich.org 70
1parent b525323a1383dfb008a8941753702e2b05d14eee /scm/ploot/commit/b525323a1383dfb008a8941753702e2b05d14eee.gph bitreich.org 70
hAuthor: Josuah Demangeon <me@josuah.net> URL:mailto:me@josuah.net bitreich.org 70
iDate: Sun, 27 Jun 2021 00:16:42 +0200 Err bitreich.org 70
i Err bitreich.org 70
ifix segmentation fault on non-ASCII glyphs Err bitreich.org 70
i Err bitreich.org 70
iDiffstat: Err bitreich.org 70
i M drawille.c | 29 ++++++++++------------------- Err bitreich.org 70
i M font.c | 6 ++++-- Err bitreich.org 70
i Err bitreich.org 70
i2 files changed, 14 insertions(+), 21 deletions(-) Err bitreich.org 70
i--- Err bitreich.org 70
1diff --git a/drawille.c b/drawille.c /scm/ploot/file/drawille.c.gph bitreich.org 70
i@@ -1,11 +1,9 @@ Err bitreich.org 70
i #include "drawille.h" Err bitreich.org 70
i- Err bitreich.org 70
i #include <stdint.h> Err bitreich.org 70
i #include <stdio.h> Err bitreich.org 70
i #include <stdlib.h> Err bitreich.org 70
i #include <string.h> Err bitreich.org 70
i #include <math.h> Err bitreich.org 70
i- Err bitreich.org 70
i #include "font.h" Err bitreich.org 70
i Err bitreich.org 70
i /* Err bitreich.org 70
i@@ -162,25 +160,18 @@ drawille_histogram_line(struct drawille *drw, int x0, int y0, int x1, int y1, in Err bitreich.org 70
i } Err bitreich.org 70
i Err bitreich.org 70
i static int Err bitreich.org 70
i-drawille_text_glyph(struct drawille *drw, int x, int y, struct font *font, char c) Err bitreich.org 70
i+drawille_text_glyph(struct drawille *drw, int x, int y, struct font *font, int c) Err bitreich.org 70
i { Err bitreich.org 70
i- int width; Err bitreich.org 70
i+ int w; Err bitreich.org 70
i char *glyph; Err bitreich.org 70
i Err bitreich.org 70
i- if ((unsigned)c > 127) Err bitreich.org 70
i- glyph = font->glyph[0]; Err bitreich.org 70
i- else Err bitreich.org 70
i- glyph = font->glyph[(unsigned)c]; Err bitreich.org 70
i- Err bitreich.org 70
i- width = strlen(glyph) / font->height; Err bitreich.org 70
i- Err bitreich.org 70
i- for (int ix = 0; ix < width; ix++) Err bitreich.org 70
i- for (int iy = 0; iy < font->height; iy++) { Err bitreich.org 70
i- if (glyph[ix + (font->height - 1) * width - iy * width] == 3) Err bitreich.org 70
i- drawille_dot(drw, x + ix, y + iy); Err bitreich.org 70
i- } Err bitreich.org 70
i- Err bitreich.org 70
i- return width; Err bitreich.org 70
i+ glyph = font->glyph[(c > 127 || c < 127) ? 0 : c]; Err bitreich.org 70
i+ w = strlen(glyph) / font->height; Err bitreich.org 70
i+ for (int ix = 0; ix < w; ix++) Err bitreich.org 70
i+ for (int iy = 0; iy < font->height; iy++) Err bitreich.org 70
i+ if (glyph[ix + (font->height - 1) * w - iy * w] == 3) Err bitreich.org 70
i+ drawille_dot(drw, x + ix, y + iy); Err bitreich.org 70
i+ return w; Err bitreich.org 70
i } Err bitreich.org 70
i Err bitreich.org 70
i char * Err bitreich.org 70
i@@ -188,7 +179,7 @@ drawille_text(struct drawille *drw, int x, int y, struct font *font, char *s) Err bitreich.org 70
i { Err bitreich.org 70
i if (drw->row*4 < font->height) Err bitreich.org 70
i return NULL; Err bitreich.org 70
i- for (; *s != '\0' && x < drw->col * 2; s++, x++) Err bitreich.org 70
i+ for (; *s != '\0' && x < drw->col*2; s++, x++) Err bitreich.org 70
i x += drawille_text_glyph(drw, x, y, font, *s); Err bitreich.org 70
i return s; Err bitreich.org 70
i } Err bitreich.org 70
1diff --git a/font.c b/font.c /scm/ploot/file/font.c.gph bitreich.org 70
i@@ -1,11 +1,13 @@ Err bitreich.org 70
i #include "font.h" Err bitreich.org 70
i- Err bitreich.org 70
i #include <string.h> Err bitreich.org 70
i Err bitreich.org 70
i size_t Err bitreich.org 70
i font_width(struct font *ft, int c) Err bitreich.org 70
i { Err bitreich.org 70
i- return strlen(ft->glyph[c]) / ft->height; Err bitreich.org 70
i+ size_t len; Err bitreich.org 70
i+ Err bitreich.org 70
i+ len = strlen(ft->glyph[(c < 0 || c > 127) ? 0 : c]) / ft->height; Err bitreich.org 70
i+ return len; Err bitreich.org 70
i } Err bitreich.org 70
i Err bitreich.org 70
i size_t Err bitreich.org 70
.
Response:
text/plain