🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #51734

malloc() problem

#51734
From: Michael P. Perrone
Date: Mon, 05 Apr 1993 15:57
43 lines
1755 bytes
HELP!

the following code produces a "Program received signal 10, Bus error"
during runtime, at the line indicated.  is there something wrong with malloc()?
i'm using gcc 2.2.2 with fixincludes (the ansi c compatible header files)
on a sparc

the parameters are rs=0, re=12, cs=0; ce=0, text="junk"

the code is:
dmat newdmat(rs, re, cs, ce, text)
        int rs, re, cs, ce;
        char *text;
        {
        register double *p, **b;
        register int r, rows, cols;
        dmat matrix;

        rows = re-rs+1;
        cols = ce-cs+1;
        if (rows<=0 || cols<=0) materror ( "newdmat", text );
        matrix.lb1 = rs;
        matrix.ub1 = re;
        matrix.lb2 = cs;
        matrix.ub2 = ce;
        b = (double **)
            malloc((unsigned)(rows*sizeof(double *) + rows*cols*sizeof(double)));
        if (b==0) materror ( "newdmat", text );
        matrix.mat_sto = (char *) b;
        p = ((double *) &b[rows]) - cs;
        matrix.el = b -= rs;
        for (r=rs; r<=re; r++)
            {
            b[r] = p;
            p += cols;
            }
ERROR-->matrix.el[0][0] = 0.3;
        return matrix;
        }

Can anyone help?
Thanks!
Michael
Technical Details
Message-ID: <1993Apr5.155717.13918@cs.brown.edu>
Path: arc1-ca.pugleaf.net!gmd.de!Germany.EU.net!mcsun!uunet!brunix!cs.brown.edu!mpp

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,94a4e6fe3e0cb8d4,start
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1993-04-05 10:04:27 PST
Newsgroups: gnu.gcc.help
Path: arc1-ca.pugleaf.net!gmd.de!Germany.EU.net!mcsun!uunet!brunix!cs.brown.edu!mpp
From: mpp@cns.brown.edu (Michael P. Perrone)
Subject: malloc() problem
Message-ID: <1993Apr5.155717.13918@cs.brown.edu>
Sender: mpp@cs.brown.edu (Michael P. Perrone)
Organization: Center for Neural Science, Brown University
Date: Mon, 5 Apr 1993 15:57:17 GMT
Lines: 43