| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Pointers |
Hello tom_torfs!
01 Sep 03 07:00, Kurt Kuzba wrote to All:
KK> You have to have the pointer, of course! To avoid accidentally
KK> attempts to free a null pointer on failure of the malloc(), you
KK> might wish to test the value of the pointer before calling free()
KK> or using the pointer to accept data intended for later use.
KK> Writing to a null pointer on an unprotected OS, such as DOS, is a
KK> very quick method for arriving at unexpected catastrophic failure.
KK> (I included fgets() lest the window shut too quick to be seen.)
Yes i know.
KK> #include
KK> #include
KK> char* test()
KK> {
KK> char* tmp = (char*)malloc(80);
KK> if(tmp) sprintf(tmp, "test");
KK> return tmp;
KK> }
KK> int main()
KK> {
KK> char* cTmp, buf[16];
KK> printf("%s", cTmp = test());
KK> if(cTmp) free(cTmp);
KK> fgets(buf, 16, stdin);
KK> return 0;
KK> }
Can't i avoid to have a extra pointer?
Regards,
Bo
--- GoldED+/LNX 1.1.5
* Origin: The Night Express, Roennede Dk (2:236/100)SEEN-BY: 633/267 270 @PATH: 236/100 237/9 20/11 106/1 2000 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.