/** Same as standard realloc(), but this one never returns null on failure. It will throw *ifitfails. *Ifsizeis0,itwillcallsk_freeonbufferandreturnnull.(Thisbehaviorisimplementation- *definedfornormalrealloc.Wefollowwhatglibcdoes.)
*/
SK_API externvoid* sk_realloc_throw(void* buffer, size_t size);
staticinlinevoid* sk_calloc_canfail(size_t size) { #ifdefined(SK_BUILD_FOR_FUZZER) // To reduce the chance of OOM, pretend we can't allocate more than 200kb. if (size > 200000) { return nullptr;
} #endif return sk_malloc_flags(size, SK_MALLOC_ZERO_INITIALIZE);
}
/** *Thesevariantsreturnnullptronfailure
*/ staticinlinevoid* sk_malloc_canfail(size_t size) { #ifdefined(SK_BUILD_FOR_FUZZER) // To reduce the chance of OOM, pretend we can't allocate more than 200kb. if (size > 200000) { return nullptr;
} #endif return sk_malloc_flags(size, 0);
}
SK_API externvoid* sk_malloc_canfail(size_t count, size_t elemSize);
// bzero is safer than memset, but we can't rely on it, so... sk_bzero() staticinlinevoid sk_bzero(void* buffer, size_t size) { // Please c.f. sk_careful_memcpy. It's undefined behavior to call memset(null, 0, 0). if (size) {
memset(buffer, 0, size);
}
}
/** *sk_careful_memcpy()isjustlikememcpy(),butguardsagainstundefinedbehavior. * *Itisundefinedbehaviortocallmemcpy()withnulldstorsrc,eveniflenis0. *Ifanoptimizeris"smart"enough,itcanexploitthistodounexpectedthings. *memcpy(dst,src,0); *if(src){ *printf("%x\n",*src); *} *Inthiscodethecompilercanassumesrcisnotnullandomittheif(src){...}check, *unconditionallyrunningtheprintf,crashingtheprogramifsrcreallyisnull. *OfthecompilerswepayattentiontoonlyGCCperformsthisoptimizationinpractice.
*/ staticinlinevoid* sk_careful_memcpy(void* dst, constvoid* src, size_t len) { // When we pass >0 len we had better already be passing valid pointers. // So we just need to skip calling memcpy when len == 0. if (len) {
memcpy(dst,src,len);
} return dst;
}
staticinlinevoid* sk_careful_memmove(void* dst, constvoid* src, size_t len) { // When we pass >0 len we had better already be passing valid pointers. // So we just need to skip calling memcpy when len == 0. if (len) {
memmove(dst,src,len);
} return dst;
}
staticinlineint sk_careful_memcmp(constvoid* a, constvoid* b, size_t len) { // When we pass >0 len we had better already be passing valid pointers. // So we just need to skip calling memcmp when len == 0. if (len == 0) { return0; // we treat zero-length buffers as "equal"
} return memcmp(a, b, len);
}
#endif// SkMalloc_DEFINED
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet am 2026-09-30)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.