Showing the changes to array.c (1 of 11 files). Show all
Unified · Split
| @@ -1,40 +1,34 @@ | ||
| 1 | 1 | #include <u.h> |
| 2 | 2 | #include <libc.h> |
| 3 | −#include <ctype.h> | |
| 3 | +#include <bio.h> | |
| 4 | 4 | #include "pdf.h" |
| 5 | 5 | |
| 6 | +/* 7.3.6 Array Objects */ | |
| 7 | + | |
| 6 | 8 | Object * |
| 7 | −pdfarray(char *p, char **e, int len) | |
| 9 | +pdfarray(Biobuf *b) | |
| 8 | 10 | { |
| 9 | 11 | Object *o, *m; |
| 10 | 12 | Object **a; |
| 11 | − | |
| 12 | − o = nil; | |
| 13 | − if(len < 3 || p[0] != '['){ | |
| 14 | − werrstr("invalid array"); | |
| 15 | − goto err; | |
| 16 | − } | |
| 17 | − p++; | |
| 18 | − len--; | |
| 13 | + int c, noel; | |
| 19 | 14 | |
| 20 | 15 | o = calloc(1, sizeof(*o)); |
| 21 | 16 | o->type = Oarray; |
| 22 | − for(; len >= 1;){ | |
| 23 | − for(; len > 0 && isws(*p); p++, len--); | |
| 24 | − if(len < 1){ | |
| 25 | − werrstr("too short"); | |
| 26 | − goto err; | |
| 27 | − } | |
| 17 | + Bgetc(b); /* throw away '[' */ | |
| 28 | 18 | |
| 29 | − if(p[0] == ']'){ | |
| 30 | − p++; | |
| 19 | + for(noel = 0;;){ | |
| 20 | + if((c = Bgetc(b)) < 0 || c == ']') | |
| 31 | 21 | break; |
| 22 | + if(noel){ | |
| 23 | + werrstr("no ']'"); | |
| 24 | + goto err; | |
| 32 | 25 | } |
| 33 | 26 | |
| 34 | − if((m = pdfobject(p, e, len)) == nil) | |
| 35 | − goto err; | |
| 36 | − len -= *e - p; | |
| 37 | − p = *e; | |
| 27 | + Bungetc(b); | |
| 28 | + if((m = pdfobject(b)) == nil){ | |
| 29 | + noel = 1; | |
| 30 | + continue; | |
| 31 | + } | |
| 38 | 32 | |
| 39 | 33 | if((a = realloc(o->array.e, (o->array.ne+1)*sizeof(Object*))) == nil){ |
| 40 | 34 | freeobject(m); |
| @@ -45,11 +39,14 @@ pdfarray(char *p, char **e, int len) · 4 unmodified lines | ||
| 45 | 39 | a[o->array.ne++] = m; |
| 46 | 40 | } |
| 47 | 41 | |
| 48 | − *e = p; | |
| 42 | + if(c != ']'){ | |
| 43 | + werrstr("no ']'"); | |
| 44 | + goto err; | |
| 45 | + } | |
| 49 | 46 | |
| 50 | 47 | return o; |
| 51 | 48 | err: |
| 49 | + werrstr("array: %r"); | |
| 52 | 50 | freeobject(o); |
| 53 | − | |
| 54 | 51 | return nil; |
| 55 | 52 | } |