printf("reading input image ... \n");
   
    /*unidata.image = (image_ptr*)read_pnm(argv[1], &(unidata.rows), &(unidata.cols), &type);
    */
   
    printf("hello.jpg");
    printf("image read successfully \n");
    printf("rows=%d, cols=%d, type=%d \n", unidata.rows, unidata.cols, type);
    /* error here*/
    printf("well");

the errors are coming between the two final printf statements. when the read_pnm() is left uncommented it is a segmentation fault, when commented it is a floating point exception. there is nothing in the code that i am aware of that would cause either.

the best i can think of is that i have somehow overrun the memory allowed to my user in the system i am on, or else the memory i have allotted to this process? either one seems very unlikely there has been very little memory used up until this point (200kb maybe?). the lack of any apparent connection makes me think i'm initiating something else (one of the libraries or something from the OS) that has a run-time error. but then again by the time it reaches the point where it should have been having this error afaik everything should have been concluded.

any help or insight anyone can give is much appreciated.

Recommended Answers

All 5 Replies

> the lack of any apparent connection makes me think i'm initiating
> something else (one of the libraries or something from the OS)
> that has a run-time error

Although possible, you should consider this as a last resort. Otherwise it will dull your mind to the more likely possibility that it is, in fact, your code that has the error.

If your code compiles, as you say it does, then clearly there is nothing in the code you posted that could produce the error (besides read_pnm, which we shall assume for the moment to be okay).

So you need to post more code. If there's a lot, you can zip it and attach it, preferably with the project files as well so those that have the same IDE can easily run it.

#include <stdio.h>
#include <stdlib.h>
#include "iplib2New.c"
#include <pthread.h>
#include <math.h>

struct celldataname
{
	int mean;
	int median;
	int deviation;
};
typedef struct celldataname celldata;

struct universalname
{
	int n;
	int maxval;
	int rows;
	int cols;
	int mode;
	int numthreads;
	celldata *calc;
	image_ptr image;
};
typedef struct universalname universal;

/*univeral variables*/
universal unidata;
pthread_mutex_t lock;

/*function prototypes*/
image_ptr read_pnm(char *filename, int *rows, int *cols, int *type);
int getnum(FILE *fp);
void write_pnm(image_ptr ptr, char *filename, int rows, int cols, int type);

int main(int argc, char **argv)
{
	int i=0, j=0, value=0, count=0, type, rc, t;

	/* check inputs */
	if (argc != 6)
	{
		printf("wrong inputs, use: %s infile outfile n mode p \n", argv[0]);  
		return 0;
	}
	
	unidata.n=atoi(argv[3]);
	unidata.mode=atoi(argv[4]);
	unidata.maxval=getMaxval(argv[1]);
	unidata.numthreads = atoi(argv[5]);
	
	if ((unidata.n%2)!=1)
	{
		printf("\'n\'-value must be odd \n");  
		return 0;
	} 
	if (unidata.mode!=1 && unidata.mode!=0)
	{
		printf("\'mode\'-value must be one or zero \n");  
		return 0;
	}
	if (unidata.numthreads<2)	
	{
		printf("\'p\'-value must be greater than or equal to two \n");  
		return 0;
	} 

	/*    first read-in the image */
	printf("reading input image ... \n");
	
	unidata.image = read_pnm(argv[1], &(unidata.rows), &(unidata.cols), &type);
	
	
	printf("hello.jpg");
	printf("image read successfully \n");
	printf("rows=%d, cols=%d, type=%d lolwut\n", unidata.rows, unidata.cols, type);
	/*error here*/
	printf("well");
	/*unidata.calc = (celldata *)malloc ((unidata.rows*unidata.cols*sizeof(celldata)));
	*/
	printf("1");

this is everything used up to the point of failure. i am unsure if i can provide the iplib2new library or the getmaxval code (was not my code), but there is nothing in them that i think would cause either of these errors. i really don't understand how this could be happening at all (a delayed failure).

int main(int argc, char **argv)
{
	
	
	int i=0, j=0, value=0, count=0, type, rc, t;
/*
	// check inputs
	if (argc != 6)
	{
		printf("wrong inputs, use: %s infile outfile n mode p \n", argv[0]);  
		return 0;
	}
	
	unidata.n=atoi(argv[3]);
	unidata.mode=atoi(argv[4]);
	unidata.maxval=getMaxval(argv[1]);
	unidata.numthreads = atoi(argv[5]);
	
	if ((unidata.n%2)!=1)
	{
		printf("\'n\'-value must be odd \n");  
		return 0;
	} 
	if (unidata.mode!=1 && unidata.mode!=0)
	{
		printf("\'mode\'-value must be one or zero \n");  
		return 0;
	}
	if (unidata.numthreads<2)	
	{
		printf("\'p\'-value must be greater than or equal to two \n");  
		return 0;
	} 
	
	printf("  well hell  there \n said the teapot typing ssheashell to the scroundel \n as he wiled away the hours singings songs of yester dour \n and as sshore as nor as not as sea \n he sailed along the destiny\n");

	//    first read-in the image
	printf("reading input image ... \n");
	
	//unidata.image = read_pnm(argv[1], &(unidata.rows), &(unidata.cols), &type);
	
	printf("image read successfully \n");
	printf("rows=%d, cols=%d, type=%d\n", unidata.rows, unidata.cols, type);
	
	*/
	
	printf("well");

same problem. this is starting to annoy.

The only line that looks like it might set up the error (through undefined behavior) is this: unidata.maxval=getMaxval(argv[1]); .

Presumably this function is in iplib2New.c. BTW, you're including the code file. Normal practice is to include a header and link with the object (or library) code.

i'm not sure if i should mark this as solved or not (who knows what else might crop up), but it's suddenly working. after testing a pretty bad design flaw has become apparent but it is not crashing any more. i think i may have actually been right about it being something out of my hands, because i can't think of what it was i did to fix it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.