History

[array] split out arrayadd

Noam Preil committed 5 years ago

Commit b0515391 parent ee088482 files · +15 −5Browse files

Unified · Split

2 files
  1. array.c +14 −5
  2. pdf.h +1 −0
array.c+14−5
@@ -8,7 +8,6 @@ Object * · 7 unmodified lines
88 pdfarray(Pdf *pdf, Stream *s)
99 {
1010 Object *o, *m;
11− Object **a;
1211 int c, noel;
1312
1413 o = calloc(1, sizeof(*o));
@@ -30,13 +29,10 @@ pdfarray(Pdf *pdf, Stream *s) · 15 unmodified lines
3029 continue;
3130 }
3231
33− if((a = realloc(o->array.e, (o->array.ne+1)*sizeof(Object*))) == nil){
32+ if(!arrayadd(o, m)){
3433 pdfobjfree(m);
3534 goto err;
3635 }
37−
38− o->array.e = a;
39− a[o->array.ne++] = m;
4036 }
4137
4238 if(c != ']'){
@@ -51,6 +47,19 @@ err: · 8 unmodified lines
5147 return nil;
5248 }
5349
50+int
51+arrayadd(Object *arr, Object *o)
52+{
53+ Object **a;
54+ a = realloc(arr->array.e, (arr->array.ne+1)*sizeof(Object*));
55+ if(a == nil)
56+ return 0;
57+ arr->array.e = a;
58+ a[arr->array.ne] = o;
59+ arr->array.ne += 1;
60+ return 1;
61+}
62+
5463 int
5564 arraylen(Object *o)
5665 {
pdf.h+1−0
@@ -190,6 +190,7 @@ int isutf8(char *s, int len); · 189 unmodified lines
190190 int arraylen(Object *o);
191191 Object *arrayget(Object *o, int i);
192192 int arrayint(Object *o, int i);
193+int arrayadd(Object *a, Object *o);
193194
194195 Object *dictget(Object *o, char *name);
195196 int dictint(Object *o, char *name);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t