🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.acorn.tech
Article #112

Re: Error trapping in C

#112
From: Pete Goodwin
Date: Thu, 06 Aug 1992 21:55
33 lines
2227 bytes
In article <1992Aug6.191108.1@vxdesy.desy.de>, burke@vxdesy.desy.de writes...

>What do you need to do to make a C program bomb-proof? You obviously have to
>catch SIGSTAK, but is it possible to get SIGINT or SIGTERM? If so, how? The C
>manual isn't very forthcoming about signals. Also, does wimpt_noerr() stop the
>program with exit() or abort()?

The answer, it seems, is you can't. If you use malloc and free you can't catch
the immortal 'malloc failure...' or 'free failure...'. On desktop applications
you effectively DON'T SEE these messages. Your application simply exits without
warning. Both these should signal _something_! Trouble is they don't!

I started using heap_alloc and heap_free, simply because if either detect an
error you get an error dialog box. The disadvantage is heap relies on flex,
which seems to bump the wimpslot up a little.

>  Secondly, what should I do after a signal? Presumably a longjmp to the main
>routine is the best bet, but what then - after a SIGSTAK, will it be safe to
>call saveas()? Or I could save to an internal file and then quit, but what if
>the save fails? Or I could put up a message and just go back to polling, but
>will all the internal data structures be intact? (and you may just get SIGSTAK
>again anyway). Acorn are always going on about how you shouldn't die with
>unsaved data, and then they give you a system whose response to running out of
>memory is to collapse with a backtrace, and no guidance on how to do it
>better :-( Any ideas?

If you read the ANSI standard, you'll see you need to do a longjmp to some
point. This works, but the next error is fatal unless you reestablish the trap
handlers again...

Pete Goodwin
goodwin@system.enet.dec.com
Technical Details
Message-ID: <1992Aug6.220054.12814@rdg.dec.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!zephyr.ens.tek.com!uw-beaver!ubc-cs!destroyer!sol.ctr.columbia.edu!usc!cs.utexas.edu!sun-barr!decwrl!deccrl!news.crl.dec.com!rdg.dec.com!edieng.enet.dec.com!goodwin

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!zephyr.ens.tek.com!uw-beaver!ubc-cs!destroyer!sol.ctr.columbia.edu!usc!cs.utexas.edu!sun-barr!decwrl!deccrl!news.crl.dec.com!rdg.dec.com!edieng.enet.dec.com!goodwin
From: goodwin@edieng.enet.dec.com (Pete Goodwin)
Newsgroups: comp.sys.acorn.tech
Subject: Re: Error trapping in C
Message-ID: <1992Aug6.220054.12814@rdg.dec.com>
Date: 6 Aug 92 21:55:19 GMT
Sender: news@rdg.dec.com (Mr News)
Organization: Digital Equipment Corporation
Lines: 33