Index: font.c
===================================================================
--- font.c	(revision 322)
+++ font.c	(revision 323)
@@ -20,7 +20,7 @@
  * @param   xpm XPM describing the glyph
  * @return      Pointer to created glyph
  */
-static glyph_t* (glyph_ctor)(const char **xpm){
+static glyph_t* (glyph_ctor)(const char *const *xpm){
     if(xpm == NULL) return NULL;
     glyph_t *ret = malloc(sizeof(glyph_t));
     if(ret == NULL) return NULL;
@@ -71,8 +71,8 @@
         for(int16_t w = 0; w < p->w; ++w){
             uint8_t a = *(p->map + w + h*p->w);
             int16_t x_ = x+w, y_ = y-p->h+h;
-            unsigned pos = x_ +y_*W;
-            alp_buf[pos] = a;
+            int32_t pos = x_ +y_*W;
+            if(0 <= pos && pos < W*H) alp_buf[pos] = a;
         }
     }
     return SUCCESS;
@@ -98,7 +98,7 @@
     for(size_t i = 0; i < ret->nchars; ++i){
         sprintf(filepath, "%s/ascii%03d.xpm2", s, i);
         char **xpm = xpm_load_xpm2(filepath);
-        ret->glyphs[i] = glyph_ctor((const char**)xpm);
+        ret->glyphs[i] = glyph_ctor((const char *const *)xpm);
         if(ret->glyphs[i] != NULL) good = true;
     }
     if(good) return ret;
@@ -137,10 +137,10 @@
     const font_t *fnt;
     char *txt;
     int16_t x, y;
-    int size;
-    uint32_t color;
+    uint16_t size;
     text_valign valign;
     text_halign halign;
+    uint32_t color;
 };
 text_t* (text_ctor)(const font_t *fnt, const char *txt){
     if(fnt == NULL) return NULL;
@@ -170,7 +170,7 @@
 }
 const char* (text_get_string)(const text_t *p){return p->txt; }
 void (text_set_pos)   (text_t *p, int16_t x, int16_t y){ p->x = x; p->y = y; }
-void (text_set_size)  (text_t *p, unsigned size       ){ p->size = size    ; }
+void (text_set_size)  (text_t *p, uint16_t size       ){ p->size = size    ; }
 void (text_set_color) (text_t *p, uint32_t color      ){ p->color = color  ; }
 void (text_set_valign)(text_t *p, text_valign valign  ){ p->valign = valign; }
 void (text_set_halign)(text_t *p, text_halign halign  ){ p->halign = halign; }
@@ -186,12 +186,12 @@
         uint16_t W = 0, H = 0; {
             for(size_t i = 0; i < len; ++i){
                 const glyph_t *g = p->fnt->glyphs[(size_t)p->txt[i]];
-                if(g != NULL){ W += g->w; H = max(H, g->h); }
+                if(g != NULL){ W += g->w; H = umax16(H, g->h); }
             }
         }
         uint8_t *alp_buf = malloc(W*H);
         if(alp_buf == NULL) return ALLOC_ERROR;{
-            int16_t y = H;
+            int16_t y = (int16_t)H;
             int16_t x = 0;
             for(size_t i = 0; i < len; ++i){
                 const glyph_t *g = p->fnt->glyphs[(size_t)p->txt[i]];
@@ -204,15 +204,15 @@
 
         double factor = (double)p->size/(double)H;
 
-        newH = H*factor;
-        newW = W*factor;
+        newH = (uint16_t)(H*factor);
+        newW = (uint16_t)(W*factor);
         alp_new_buf = malloc(newW*newH);
         if(alp_new_buf == NULL) return ALLOC_ERROR;
 
-        for(size_t newy = 0; newy < newH; ++newy){
-            size_t y = newy/factor;
-            for(size_t newx = 0; newx < newW; ++newx){
-                size_t x = newx/factor;
+        for(uint16_t newy = 0; newy < newH; ++newy){
+            uint16_t y = (uint16_t)(newy/factor);
+            for(uint16_t newx = 0; newx < newW; ++newx){
+                uint16_t x = (uint16_t)(newx/factor);
                 *(alp_new_buf+newx+newy*newW) = *(alp_buf+x+y*W);
             }
         }
@@ -224,7 +224,7 @@
             case text_halign_left  : initx = p->x         ; break;
             case text_halign_center: initx = p->x - newW/2; break;
             case text_halign_right : initx = p->x - newW  ; break;
-            default: return LOGIC_ERROR;
+            //default: return LOGIC_ERROR;
         }
     }
     // Get initial value of y
@@ -233,7 +233,7 @@
             case text_valign_top   : inity = p->y         ; break;
             case text_valign_center: inity = p->y - newH/2; break;
             case text_valign_bottom: inity = p->y - newH  ; break;
-            default: return LOGIC_ERROR;
+            //default: return LOGIC_ERROR;
         }
     }
     // Draw text
@@ -244,7 +244,7 @@
             if(!(0 <= x && x < graph_get_XRes() &&
                  0 <= y && y < graph_get_YRes())) continue;
             uint8_t a = *(alp_new_buf+newx+newy*newW);
-            if(a < ALPHA_THRESHOLD) graph_set_pixel(x,y,p->color);
+            if(a < ALPHA_THRESHOLD) graph_set_pixel((uint16_t)x,(uint16_t)y,p->color);
         }
     }
     free(alp_new_buf);
