History

[array] split out arrayadd

Noam Preil committed 5 years ago

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

Showing the changes to array.c (1 of 2 files). Show all

Unified · Split

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 {

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