我正在使用Totalview来调试一些代码,它正在以总线错误停止。
这是什么,我该如何解决?这是代码片段
在我的主要:
char *infilename = "/home/dcole/Images/lena1024s.jpg";
/* Try opening a jpeg*/
if( read_jpeg_file( infilename ) > 0 )
{
//do some stuff
}
功能:
int read_jpeg_file( const char *filename )
{
/* these are standard libjpeg structures for reading(decompression) */
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
/* libjpeg data structure for storing one row, that is, scanline of an image */
JSAMPROW row_pointer[1];
FILE *infile = fopen( filename, "rb" ); //this line is where the debugger stops with a Bus Error
unsigned long location = 0;
int i = 0;
if ( !infile )
{
printf("Error opening jpeg file %s\n!", filename );
return -1;
}
return 1;
}
我传入的文件确实存在。我可以看到它显示为调试器中完整路径的正确位置。
答案 0 :(得分:-1)
我认为由于文件名变量而导致内存访问问题... 代替: char * infilename =“/ home / dcole / images / lena1024s.jpg”;
尝试使用: char infilename [] =“/ home / dcole / images / lena1024s.jpg”;