Permalink
Browse files

Fix append_char() bug (unterminated empty string)

  • Loading branch information...
Sound and Fury
Sound and Fury committed Aug 21, 2010
1 parent 2b3007c commit b0003d6689db9a8c0629317a7a89f1728c454312
Showing with 15 additions and 3 deletions.
  1. +8 −0 bits.c
  2. +1 −0 bits.h
  3. +2 −3 buffer.c
  4. +4 −0 plans
View
8 bits.c
@@ -145,6 +145,14 @@ void append_char(char **buf, int *l, int *i, char c)
(*buf)[*i]=0;
}
+void init_char(char **buf, int *l, int *i)
+{
+ *l=80;
+ *buf=(char *)malloc(*l);
+ (*buf)[0]=0;
+ *i=0;
+}
+
void crush(char **buf, int len)
{
if(strlen(*buf)>len)
View
1 bits.h
@@ -21,6 +21,7 @@
char * fgetl(FILE *); // gets a line of string data; returns a malloc-like pointer (preserves trailing \n)
int wordline(char *, int x, char **); // prepares a string for printing, breaking lines in between words
+void init_char(char **buf, int *l, int *i); // initialises a string buffer in heap. *buf becomes a malloc-like pointer
void append_char(char **buf, int *l, int *i, char c); // adds a character to a string buffer in heap (and realloc()s if needed)
void crush(char **buf, int len);
void scrush(char **buf, int len);
View
@@ -259,9 +259,8 @@ void in_update(char *inp)
char *highlight(char *src)
{
- int l=80;
- char *rv=(char *)malloc(l);
- int i=0;
+ int l,i;char *rv;
+ init_char(&rv, &l, &i);
while(*src)
{
if(*src=='\\')
View
4 plans
@@ -14,6 +14,10 @@ Input editing. Should use something based on Emacs line editing keys (C-a will
wordline() spaces. Currently, wordline() replaces /[ \t]+/ with a single space. This messes up ASCII art (like TFnet's MOTD)
+append_char(). This should be used for all string appension (eg. fgetl())
+
+quoting/escaping tables. Instead of duplicative hard-baked logic, we should have a data-driven system with a single point of truth.
+
Top status bar. Carry the info in the xterm title and maybe more info besides. Here's an idea for a layout that nicely fits things in.
| 0 16 0 16 0 12
1 8 18 29 48 67 80

0 comments on commit b0003d6

Please sign in to comment.