diff util.c @ 431:a9b20b31cae1

More code cleanups, this time using clang with excessive warnings enabled. Also re-added util.h, that was missing. Oops.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 24 May 2012 20:57:06 +0300
parents d015ecbd231d
children 3396acd40147
line wrap: on
line diff
--- a/util.c	Thu May 24 14:10:47 2012 +0300
+++ b/util.c	Thu May 24 20:57:06 2012 +0300
@@ -109,7 +109,7 @@
                 int i = nn_get_hexdigit(*(++s), 0);
                 if (i >= 0)
                 {
-                    PUSHCHAR(c | i);
+                    PUSHCHAR((char) (c | i));
                 }
                 else
                 {
@@ -234,7 +234,7 @@
             for (i = 0; i < numHTMLEntities; i++)
             {
                 const html_entity_t *ent = &HTMLEntities[i];
-                int len = strlen(ent->ent);
+                size_t len = strlen(ent->ent);
                 if (!strncmp(s, ent->ent, len))
                 {
                     PUSHCHAR(ent->c);
@@ -282,13 +282,11 @@
 }
 
 
-int nn_editbuf_write(nn_editbuf_t *buf, ssize_t pos, int ch)
+int nn_editbuf_write(nn_editbuf_t *buf, size_t pos, char ch)
 {
     if (buf->len+1 >= buf->size) return -3;
 
-    if (pos < 0)
-        return -1;
-    else if (pos >= buf->len)
+    if (pos >= buf->len)
         buf->data[buf->len++] = ch;
     else
         buf->data[pos] = ch;
@@ -297,13 +295,11 @@
 }
 
 
-int nn_editbuf_insert(nn_editbuf_t *buf, ssize_t pos, int ch)
+int nn_editbuf_insert(nn_editbuf_t *buf, size_t pos, char ch)
 {
     if (buf->len+1 >= buf->size) return -3;
 
-    if (pos < 0)
-        return -1;
-    else if (pos >= buf->len)
+    if (pos >= buf->len)
     {
         buf->data[buf->len] = ch;
     }
@@ -317,11 +313,9 @@
 }
 
 
-int nn_editbuf_delete(nn_editbuf_t *buf, ssize_t pos)
+int nn_editbuf_delete(nn_editbuf_t *buf, size_t pos)
 {
-    if (pos < 0)
-        return -1;
-    else if (pos < buf->len)
+    if (pos < buf->len)
     {
         memmove(&(buf->data[pos]), &(buf->data[pos+1]), buf->len - pos);
         buf->len--;
@@ -339,7 +333,7 @@
 }
 
 
-nn_editbuf_t * nn_editbuf_new(ssize_t n)
+nn_editbuf_t * nn_editbuf_new(size_t n)
 {
     nn_editbuf_t *res = th_calloc(1, sizeof(nn_editbuf_t));
 
@@ -378,25 +372,19 @@
 }
 
 
-char * nn_editbuf_get_string(nn_editbuf_t *buf, ssize_t start, ssize_t end)
+char * nn_editbuf_get_string(nn_editbuf_t *buf, size_t start, size_t end)
 {
     char *str;
-    ssize_t siz;
+    size_t siz;
 
     if (buf == NULL)
         return NULL;
 
-    if (start < 0 || end > buf->len || start >= buf->len)
+    if (end > buf->len || start >= buf->len)
         return NULL;
 
-    if (end < 0)
-    {
-        siz = buf->len - start + 1;
-    }
-    else if (start <= end)
-    {
+    if (start <= end)
         siz = end - start + 1;
-    }
     else
         return NULL;
 
@@ -410,13 +398,11 @@
 }
 
 
-void nn_editbuf_setpos(nn_editbuf_t *buf, ssize_t pos)
+void nn_editbuf_setpos(nn_editbuf_t *buf, size_t pos)
 {
     assert(buf != NULL);
 
-    if (pos < 0)
-        buf->pos = 0;
-    else if (pos >= buf->len)
+    if (pos >= buf->len)
         buf->pos = buf->len;
     else
         buf->pos = pos;
@@ -438,7 +424,7 @@
     
     return (hash & 0xff);
 */
-    return tolower(name[0]);
+    return (uint8_t) tolower(name[0]);
 }