File tree Expand file tree Collapse file tree 2 files changed +26
-11
lines changed
test/standalone/asprintf_fprintf/src Expand file tree Collapse file tree 2 files changed +26
-11
lines changed Original file line number Diff line number Diff line change 77_calloc:
88 pop de
99 pop bc
10- ex (sp),hl
10+ ex (sp), hl
1111 push bc
1212 push de
1313 call __imulu
1414 push hl
1515 push hl
1616 call _malloc
17- pop de
18- add hl,de
19- xor a,a
20- sbc hl,de
21- ld e,a
22- push de
17+ pop bc ; reset SP
18+ ; test for NULL
19+ add hl, bc
20+ or a, a
21+ sbc hl, bc
22+ pop bc ; BC = size
23+ ret z ; return NULL
24+ ; inlined bzero
2325 push hl
24- call nz,_memset
25- pop de
26- pop de
27- pop de
26+ ex de, hl ; DE = dest
27+ ; test if the size is zero
28+ scf
29+ sbc hl, hl
30+ add hl, bc
31+ jr nc, .finish
32+ ; large region of all zeros on the Ti84CE
33+ ld hl, $E40000 ; HL = src
34+ ldir
35+ .finish:
36+ pop hl ; return value
2837 ret
2938
3039if defined ALLOCATOR_SIMPLE
Original file line number Diff line number Diff line change @@ -415,6 +415,12 @@ int memccpy_tests(void) {
415415 return __LINE__ ;
416416 }
417417
418+ /* check that no crashes occur with small calloc sizes */
419+ buf = (char * )calloc (1 , sizeof (char ));
420+ free (buf );
421+ buf = (char * )calloc (0 , sizeof (char ));
422+ free (buf );
423+
418424 buf = (char * )calloc (file_size + 1 , sizeof (char ));
419425 if (buf == NULL ) {
420426 perror ("calloc failure" );
You can’t perform that action at this time.
0 commit comments