Martin is clearly right! Here are the corrected diffs.

-----Original Message-----
From: Martin Husemann <mar...@netbsd.org> 
Sent: Friday, December 27, 2024 2:04 PM
To: Lupien, John <jlup...@draper.com>
Cc: openocd-devel@lists.sourceforge.net
Subject: [EXTERNAL] Re: ctype issue

CAUTION: This email originated from outside of the organization. Do not click 
links or open attachments unless you recognize the sender and know the content 
is safe.


On Fri, Dec 27, 2024 at 05:30:23PM +0000, Lupien, John wrote:
> I have corrected these build errors and gotten a clean build, here is the 
> diff.

Casting to int is not good when char is unisnged on a platform.
The correct way to call the ctype predicates on elements of a char* buffer is 
like this:

        isprint((int)(unsigned char)*argv[1])

that way the char value is made unsigned explicitly, then converted to int and 
then passed to isprint. Usually the (int) cast is optional (if isprint is a 
function, argument promotion rules will imply the (int), if it is a macro it 
usually is written in a way to allow the (unsigned char) argument).

If your platform uses signed chars your patch does not change anything (but 
eroneously supress the warnings).

See the CAVEATS section here for a reasonable good explanation:

        
https://urldefense.us/v2/url?u=https-3A__man.netbsd.org_ctype.3&d=DwIBAg&c=m5mye7XjY-PNBUdjUS9G7n0DDGwujM2TWPAftzw2VTE&r=ILTxQ-BydeKdMcD7cBYXJnoLPJ7Afuxo693QbxGGh2g&m=01k9A4FcugNH75hucVhVcT5J3mZQqw81e2Vi1KvL8pnrI5-_brhuRn9GLRFKBE6z&s=XrxyDB-c192mcFCNcLfDSRsRDO1vlh6D1vca2MHhfO8&e=

Martin

Attachment: diffs
Description: diffs



Reply via email to