Introduction
Introduction Statistics Contact Development Disclaimer Help
fix segmentation fault on non-ASCII glyphs - ploot - simple plotting tools
git clone git://bitreich.org/ploot git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65…
Log
Files
Refs
Tags
README
LICENSE
---
commit c3fcef87d156b02a9ad8ca7cd47fee4a826534f4
parent b525323a1383dfb008a8941753702e2b05d14eee
Author: Josuah Demangeon <[email protected]>
Date: Sun, 27 Jun 2021 00:16:42 +0200
fix segmentation fault on non-ASCII glyphs
Diffstat:
M drawille.c | 29 ++++++++++-------------------
M font.c | 6 ++++--
2 files changed, 14 insertions(+), 21 deletions(-)
---
diff --git a/drawille.c b/drawille.c
@@ -1,11 +1,9 @@
#include "drawille.h"
-
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
-
#include "font.h"
/*
@@ -162,25 +160,18 @@ drawille_histogram_line(struct drawille *drw, int x0, int…
}
static int
-drawille_text_glyph(struct drawille *drw, int x, int y, struct font *font, cha…
+drawille_text_glyph(struct drawille *drw, int x, int y, struct font *font, int…
{
- int width;
+ int w;
char *glyph;
- if ((unsigned)c > 127)
- glyph = font->glyph[0];
- else
- glyph = font->glyph[(unsigned)c];
-
- width = strlen(glyph) / font->height;
-
- for (int ix = 0; ix < width; ix++)
- for (int iy = 0; iy < font->height; iy++) {
- if (glyph[ix + (font->height - 1) * width - iy * width] == 3)
- drawille_dot(drw, x + ix, y + iy);
- }
-
- return width;
+ glyph = font->glyph[(c > 127 || c < 127) ? 0 : c];
+ w = strlen(glyph) / font->height;
+ for (int ix = 0; ix < w; ix++)
+ for (int iy = 0; iy < font->height; iy++)
+ if (glyph[ix + (font->height - 1) * w - iy * w] == 3)
+ drawille_dot(drw, x + ix, y + iy);
+ return w;
}
char *
@@ -188,7 +179,7 @@ drawille_text(struct drawille *drw, int x, int y, struct fo…
{
if (drw->row*4 < font->height)
return NULL;
- for (; *s != '\0' && x < drw->col * 2; s++, x++)
+ for (; *s != '\0' && x < drw->col*2; s++, x++)
x += drawille_text_glyph(drw, x, y, font, *s);
return s;
}
diff --git a/font.c b/font.c
@@ -1,11 +1,13 @@
#include "font.h"
-
#include <string.h>
size_t
font_width(struct font *ft, int c)
{
- return strlen(ft->glyph[c]) / ft->height;
+ size_t len;
+
+ len = strlen(ft->glyph[(c < 0 || c > 127) ? 0 : c]) / ft->height;
+ return len;
}
size_t
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.