URI: 
       fix segmentation fault on non-ASCII glyphs - ploot - simple plotting tools
  HTML git clone git://bitreich.org/ploot git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/ploot
   DIR Log
   DIR Files
   DIR Refs
   DIR Tags
   DIR README
   DIR LICENSE
       ---
   DIR commit c3fcef87d156b02a9ad8ca7cd47fee4a826534f4
   DIR parent b525323a1383dfb008a8941753702e2b05d14eee
  HTML Author: Josuah Demangeon <me@josuah.net>
       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(-)
       ---
   DIR 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 y0, int x1, int y1, in
        }
        
        static int
       -drawille_text_glyph(struct drawille *drw, int x, int y, struct font *font, char c)
       +drawille_text_glyph(struct drawille *drw, int x, int y, struct font *font, int c)
        {
       -        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 font *font, char *s)
        {
                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;
        }
   DIR 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