drawing images with opengl

Hi All
I have:
unsigned char* imagedata.
I also have a function(pnm.c) that reads in a greyscale pgm image and return a pointer to the beginning of data. this is stored in " imagedata".
then to display the image i use the following:

glDrawPixels(w,h,GL_LUMINANCE,GL_UNSIGNED_BYTE,(const uchar*)imagedata);

w,h are the width and height of the image.

but when i run the program i get a memory read error. it says memory cannot be read.

Can someone suggest me a fix to this problem???
thanx in advance.

Try using glPixelStorei(GL_UNPACK_ALIGNMENT,1).
This way OpenGL wont try to align rows to the standard 4byte boundaries.