cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/08/16/21:00:33

From: DavMac AT iname DOT com (Davin McCall)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: help me with this bmp loader program please
Date: Mon, 16 Aug 1999 05:19:09 GMT
Organization: Monash Uni
Lines: 32
Distribution: world
Message-ID: <37b79ddd.20183500@newsserver.cc.monash.edu.au>
References: <7p83hn$cml$1 AT nnrp1 DOT deja DOT com>
NNTP-Posting-Host: damcc5.halls.monash.edu.au
X-Trace: towncrier.cc.monash.edu.au 934780691 27728 130.194.198.138 (16 Aug 1999 05:18:11 GMT)
X-Complaints-To: abuse AT monash DOT edu DOT au
NNTP-Posting-Date: 16 Aug 1999 05:18:11 GMT
X-Newsreader: Forte Free Agent 1.1/32.230
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Easy. You declare "char *pix" in function "main" and pass it to
"GetBitmap" without actually setting it to a suitable value

	(eg:   char *pix = malloc(BIG_NUMBER); )

GetBitmap then stores values at the memory pointed to by pix, which
could be anywhere... your program crashes!

A better way of doing this would be to have:


int GetBitmap(char* file, char** pix, int *width, int * height);

("pix" parameter is now char **, not char *) and then in the code for
GetBitmap:

  
  *pix = malloc( paddedWidth * bmpheader.biHeight );

//********problem area *************//
   for(int i=0; i < bmpheader.biHeight; i++)
      fread((*pix)[i*paddedWidth] , paddedWidth,1 , bmpfile);
    /* notice change from "pix" to "{*pix)" in above line */
//************************************


Davin.

[original snipped]
__________________________________________________________
       *** davmac - sharkin'!! davmac AT iname DOT com ***
my programming page: http://yoyo.cc.monash.edu.au/~davmac/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019