🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #1051

Lattice C 5.02 BUGS

#1051
From: Peter Chubb
Date: Mon, 28 Aug 1989 23:05
77 lines
2542 bytes
Some more bugs in Lattice C 5.02 for the Amiga for your pleasure and
delectation:

Compiler bug:

void t()
{	long a, *t;

	*t = (*t < a);
}

Instead of a compare instruction, the compiler generates an exclusive or
instruction.  These have the same bit pattern, but are interpreted
differently depending on the addressing mode.

Library bugs:

getenv() seems to use the same buffer for the name of the file in env: and
its returned contents.  Unfortunately, if the file name was longer than the
value of the variable, the end of the file name will still be visible.
Maybe it's not being null terminated properly?
I've appended a version of getenv that works.  This version uncovered a bug
in the builtin_strcpy, too!

fork() often seems to crash the amiga.  Try the example in the manual with
c:echo as argument, just be ready for the three-fingered reset.

----------------Cut Here------------------------------------
/************************************************************************
 * getenv.c -- get environment variable value.				*
 *									*
 *		Copyright 1989 Peter Chubb				*
 *		All rights reserved					*
 *									*
 *		This software may be used and distributed freely	*
 *		providing this notice is not removed or altered		*
 *		and any changes to the file are clearly marked as	*
 *		such.							*
 *									*
 ************************************************************************/

#include <stdio.h>
#include <string.h>
#include <proto/dos.h>

#undef strcpy	/* avoid bug in built_in strcpy */

/* getenv -- return value of 1.3 environment variable */
char *
getenv(char *name)
{
    static char buf[BUFSIZ];
    BPTR   envfile;
    long   len;

    if(!name)
	return NULL;

    (void)strcpy(buf, "ENV:");
    (void)strcat(buf, name);

    if((envfile = Open(buf, MODE_OLDFILE)) == (BPTR)0)
	return NULL; /* non-existent variable */

    if((len = Read(envfile, buf, BUFSIZ)) < 0){
	(void)Close(envfile);
	return NULL;
    }

    if(len != BUFSIZ)
	buf[len] = '\0';
    else /* too long */
	buf[BUFSIZ-1] = '\0';

    (void)Close(envfile);
    return buf;
}
Technical Details
Message-ID: <2023@softway.oz>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ames!uhccux!munnari.oz.au!murtoa.cs.mu.oz.au!otc!softway!peterc

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ames!uhccux!munnari.oz.au!murtoa.cs.mu.oz.au!otc!softway!peterc
From: peterc@softway.oz (Peter Chubb)
Newsgroups: comp.sys.amiga.tech
Subject: Lattice C 5.02 BUGS
Keywords: cmp==eor getenv fork
Message-ID: <2023@softway.oz>
Date: 28 Aug 89 23:05:48 GMT
Organization: Softway Pty Ltd, Sydney, Australia
Lines: 77