File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed
test/standalone/asprintf_fprintf/src Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 4
4
public _malloc, _free, _realloc
5
5
6
6
public _calloc
7
+
8
+ if defined __TICE__
9
+
10
+ ; uses the hardware specific $E40000 memory location
11
+
12
+ ; void *calloc(size_t nmemb, size_t size)
13
+ _calloc:
14
+ pop de
15
+ pop bc
16
+ ex (sp), hl
17
+ push bc
18
+ push de
19
+ call __imulu
20
+ push hl
21
+ push hl
22
+ call _malloc
23
+ pop bc ; reset SP
24
+ ; test for NULL
25
+ add hl, bc
26
+ or a, a
27
+ sbc hl, bc
28
+ pop bc ; BC = size
29
+ ret z ; return NULL
30
+ ; inlined bzero
31
+ push hl
32
+ ex de, hl ; DE = dest
33
+ ; test if the size is zero
34
+ scf
35
+ sbc hl, hl
36
+ add hl, bc
37
+ jr nc, .finish
38
+ ; large region of all zeros on the Ti84CE
39
+ ld hl, $E40000 ; HL = src
40
+ ldir
41
+ .finish:
42
+ pop hl ; return value
43
+ ret
44
+
45
+ else
46
+
47
+ ; makes no hardware assumptions
48
+
49
+ ; void *calloc(size_t nmemb, size_t size)
7
50
_calloc:
8
51
pop de
9
52
pop bc
@@ -27,6 +70,8 @@ _calloc:
27
70
pop de
28
71
ret
29
72
73
+ end if
74
+
30
75
if defined ALLOCATOR_SIMPLE
31
76
32
77
_malloc := __simple_malloc
Original file line number Diff line number Diff line change @@ -418,6 +418,12 @@ int memccpy_tests(void) {
418
418
return __LINE__ ;
419
419
}
420
420
421
+ /* check that no crashes occur with small calloc sizes */
422
+ buf = (char * )calloc (1 , sizeof (char ));
423
+ free (buf );
424
+ buf = (char * )calloc (0 , sizeof (char ));
425
+ free (buf );
426
+
421
427
buf = (char * )calloc (file_size + 1 , sizeof (char ));
422
428
if (buf == NULL ) {
423
429
perror ("calloc failure" );
You can’t perform that action at this time.
0 commit comments