JPEG/setjmp always fails

  • Follow


Hi,

I'm working on a project where we had a function that loads a jpeg
file.
I moved that function into a class that handles images without
modifications but
now setjmp never returns 0 anymore under win32.
The code still works under Linux and MacOS X though.

Any idea why setjmp would always return something !=0 only under win32
??

Any help is greatly appreciated, thanks.

Here is the beginning code (full file at
http://ewave.homelinux.org/vegastrike/vsimage.cpp) :

	my_error_mgr jerr;
	JSAMPARRAY row_pointers=NULL;// Output row buffer

	cinfo.err = jpeg_std_error(&jerr.pub);
	jerr.pub.error_exit = my_error_exit;

	int val;

	if ((val=setjmp(jerr.setjmp_buffer)))
	{
         .......

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply surfdargent 9/27/2003 2:46:34 PM

On 27 Sep 2003 10:46:34 -0400, surfdargent@free.fr (St?phane
Vaxelaire) wrote in comp.lang.c++.moderated:

 > Hi,
 >
 > I'm working on a project where we had a function that loads a jpeg
 > file.
 > I moved that function into a class that handles images without
 > modifications but
 > now setjmp never returns 0 anymore under win32.
 > The code still works under Linux and MacOS X though.
 >
 > Any idea why setjmp would always return something !=0 only under win32
 > ??
 >
 > Any help is greatly appreciated, thanks.
 >
 > Here is the beginning code (full file at
 > http://ewave.homelinux.org/vegastrike/vsimage.cpp) :
 >
 >       my_error_mgr jerr;
 >       JSAMPARRAY row_pointers=NULL;// Output row buffer
 >
 >       cinfo.err = jpeg_std_error(&jerr.pub);
 >       jerr.pub.error_exit = my_error_exit;
 >
 >       int val;
 >
 >       if ((val=setjmp(jerr.setjmp_buffer)))
 >       {

You are calling setjmp in a manner not guaranteed to have defined
behavior.  Note that the C++ standard does not specifically define the
operation of setjmp(), but refers to the C standard, which states:

========
An invocation of the setjmp macro shall appear only in one of the
following contexts:

— the entire controlling expression of a selection or iteration
statement;

— one operand of a relational or equality operator with the other
operand an integer constant expression, with the resulting expression
being the entire controlling expression of a selection or iteration
statement;

— the operand of a unary ! operator with the resulting expression
being the entire controlling expression of a selection or iteration
statement; or

— the entire expression of an expression statement (possibly cast to
void).

5 If the invocation appears in any other context, the behavior is
undefined.
========

Now this may not be your problem, but assigning the value returned by
setjmp() results in undefined behavior under the language standard.

If you must save the actual value returned without invoking undefined
behavior, you need to use a switch statement:

switch (setjmp(jerr.setjmp_buffer))
{
     case 0:
       val = 0;
       break;

     case SOME_VALUE:
       val = SOME_VALUE;
       break;

// etc.
}

If you eliminate the assignment one way or another and your program
still has the error, you have a valid complaint, assuming you have all
current service packs installed.  If the program works with the
assignment eliminated, the compiler is within its rights, no matter
how inconvenient it may seem to you.

-- 
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply Jack 9/28/2003 10:25:05 AM


1 Replies
145 Views

(page loaded in 0.737 seconds)


Reply: