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 44 public _malloc, _free, _realloc
55
66 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)
750_calloc:
851 pop de
952 pop bc
@@ -27,6 +70,8 @@ _calloc:
2770 pop de
2871 ret
2972
73+ end if
74+
3075if defined ALLOCATOR_SIMPLE
3176
3277_malloc := __simple_malloc
Original file line number Diff line number Diff line change @@ -418,6 +418,12 @@ int memccpy_tests(void) {
418418 return __LINE__ ;
419419 }
420420
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+
421427 buf = (char * )calloc (file_size + 1 , sizeof (char ));
422428 if (buf == NULL ) {
423429 perror ("calloc failure" );
You can’t perform that action at this time.
0 commit comments