Bug 692347

Summary: "Assertion failed! (unsigned)(c + 1) <= 256" with extended chars in GS_OPTIONS
Product: Ghostscript Reporter: SaGS <sags5495>
Component: GeneralAssignee: Default assignee <ghostpdl-bugs>
Status: RESOLVED FIXED    
Severity: normal CC: alex
Priority: P4    
Version: master   
Hardware: PC   
OS: Windows XP   
Customer: Word Size: ---
Attachments: Suggested patch.

Description SaGS 2011-07-16 19:01:33 UTC
The following sequence of commands:

    set GS_OPTIONS=-dMéditéranéen
    gswin32c

leads to:

    Debug Assertion failed!
    File: isctype.c [this one is from the C RunTime, not from GS]
    Expression: (unsigned)(c + 1) <= 256

Ghostscript compiled on Windows using Visual Studio .NET 2003.

Cause:

    VS treats the "char" type as signed by default. This means 
    that when extended characters are promoted to ints, the values
    are negative in the range -128 to -1. These values (except -1
    which conflicts with EOF) are not valid for the "is*()" family 
    of functions. GS does exhibit this problem while parsing the
    GS_OPTIONS. Not sure if this can ever happen with command line 
    arguments or @files.

This does not seem to be a regression, the SVN history shows the 
affected part as being from revision 2 (but it is older for sure).
Comment 1 SaGS 2011-07-16 19:03:07 UTC
Created attachment 7678 [details]
Suggested patch.

Bug 692347: "Assertion failed! (unsigned)(c + 1) <= 256" with extended chars in GS_OPTIONS.

In some circumstances, characters from the arguments are passed to
"isspace()", which expects an int argument in the rage 0..255 or the
value EOF. In the char type is signed, character values of 128 and
larger are considered negative, and promoted to negative integers
outside the range accepted by "isspace()".
Comment 2 Alex Cherepanov 2011-07-29 18:52:43 UTC
This patch has been committed by Ray on 2011-07-17 as a rev.
44a2fd0bb1e2dd12e9ba475da0bdbb93081325d5