[net.sources.games] larn seg. viol. bug fix

toma@fluke.UUCP (Tom Anderson) (07/09/86)

*** REPLACE THIS LINE WITH YOUR ORB OF NYMPH CONTROL ***

Well, I found at least one source of a segmentation violation in 
Larn that can plague winners upon arriving home.  We have been
using the vt100 emulator program that was posted to the net to
play Larn on the Suns around here.  When one does that, getlogin()
fails and returns a null pointer.  This screws up the twelfth line
in bill.c:

    strcpy(logname, getlogin());

Strangely, logname[] is already properly initialized in main.c,
so we have merely commented the above line out in bill.c.

BTW, the code in main.c resorts to examining the environment for
something bound to USER in the event getlogin() fails.  A "better"
way is to use the following:

    #include <pwd.h>

    ...

    struct passwd * pwe;

    if ((pwe = getpwuid(getuid())) != (struct passwd *) 0) {
	strcpy(logname, pwe-pw_name);
    } else {
	...
    }

-- 


                           Tom Anderson
                           John Fluke Mfg. Co., Inc.
                           P.O. Box C9090 M/S 245F
                           Everett, Washington 98206
                           (206) 356-5895

            { hplsla, microsoft, ssc-vax, sunup, telematic, tikal, 
            uw-beaver, uw-vlsi, lbl-csam, sb1, sb6, sun }!fluke!toma