tfra@ur-tut.UUCP (Thomas Fravenhofer) (12/08/85)
I am trying to get a screen editor working on my Fortune 32:16 system. It keeps crashing in the routine "_doprnt" (giving me a memory addressing error). I can't seem to find any documentation on it. Does anyone have some documentation on this function? My system runs FOR:PRO 1.7, which is a version 7 derivative with a little 4.1 thrown it (as little as they could get away with, anyway...). Thanks in advance. Tom
gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>) (12/10/85)
> I am trying to get a screen editor working on my Fortune 32:16 system. It > keeps crashing in the routine "_doprnt" (giving me a memory addressing error). > I can't seem to find any documentation on it. _doprnt() is used internally by the printf() family of functions. One common cause of crashes in it is passing a bum pointer for a %s format spec, or not having the correct number of arguments.
olson@fortune.UUCP (Dave Olson) (12/12/85)
As I'm sure you'll hear from many people, _doprnt is undocumented because it is not guaranteed to exist. On many V7 derived unix's it is used to implement printf, sprintf, and fprintf. NOTE: there are some more general comments at the end of this article, but the main part is specific to Fortune Systems products. If you are using the 1.7 LDT release from Fortune (try running 'what /usr/lib/libc.a' to get the version), the problem is probably due to the fact that doprnt was compiled with stack checking turned off. Most of the library routines were compiled this way for the sake of speed. Unfortunately, several routines (I believe they were just ecvt() and _doprnt(), but don't hold me to it :-) ) use quite a bit of stack for local variables (about 440 bytes for _doprnt()). As a result, when these routines are called, and a program is approaching the max stack allocated (initially 9K, and grows when a routine with stack checking on is called) calls printf(), you get a segmentation violation. There are two ways to fix this problem. The 'best' is to get the current Fortune LDT release (1.8.2). The second solution is to call a dummy routine that has a large local array. You'll have to experiment to see at what point you'll need to call it, or call it early in the program and make it a very large array. Stack is normally allocated in 8K increments by the kernel. The dummy routine doesn't have to do anything, just make sure it is in a file compiled WITHOUT the -G option. You can determine how much stack is allocated by running the command: pstat -u PID 1 | grep ssize where PID is the process ID of your program, and the '1' says to run pstat at one second intervals. MORE GENERAL QUESTIONS: I'm posting this here because it may be of general interest. More generally, how do other systems using the 68000 (NOT the 68010 or 68020, which allow you to restart an instruction on address errors) do stack checking, or do they do it at all? Fortune does it by calling a routine (csav, or csavl if floating point is used) to be sure sufficient stack is available at entry to a function. This call is inserted by the compiler, and assumes 'normal' conventions are followed; it may not work if you are using assembly language routines. It still has a problem when someone (generally a novice programmer) calls a routine with a LARGE strucure (NOT a pointer) as an argument. Dave Olson, Fortune Systems
mikel@codas.UUCP (Mikel Manitius) (12/18/85)
> > I am trying to get a screen editor working on my Fortune 32:16 system. It > > keeps crashing in the routine "_doprnt" (giving me a memory addressing error). > > I can't seem to find any documentation on it. > > _doprnt() is used internally by the printf() family of functions. > One common cause of crashes in it is passing a bum pointer for a > %s format spec, or not having the correct number of arguments. A common missuse of scanf and sprintf, is calling by value and not by address. The target variable should be called by address. -- Mikel Manitius @ AT&T-IS Altamonte Springs, FL ...{ihnp4|akgua|bellcore|clyde|koura}!codas!mikel
gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>) (12/21/85)
> > > I am trying to get a screen editor working on my Fortune 32:16 system. It > > > keeps crashing in the routine "_doprnt" (giving me a memory addressing error). > > > I can't seem to find any documentation on it. > > > > _doprnt() is used internally by the printf() family of functions. > > One common cause of crashes in it is passing a bum pointer for a > > %s format spec, or not having the correct number of arguments. > > A common missuse of scanf and sprintf, is calling by value and > not by address. The target variable should be called by address. All the printf family are called by value. What you say is try for scanf family usage errors, though.