cups icon indicating copy to clipboard operation
cups copied to clipboard

[WIP] Clang-tidy fixes

Open AZero13 opened this issue 4 years ago • 8 comments

All of these nonfunctional changes were suggested by clang-tidy, especially replacing new with malloc when necessary and doing the appropriate responses instead of just throwing an unhandled error.

AZero13 avatar Sep 08 '21 20:09 AZero13

All issues addressed!

AZero13 avatar Sep 09 '21 15:09 AZero13

Done!

AZero13 avatar Sep 13 '21 22:09 AZero13

@AtariDreams It looks like this PR has picked up the removal of "& 255" changes, which are part of another PR. I can't merge as-is...

michaelrsweet avatar Sep 17 '21 13:09 michaelrsweet

Only calls to char functions that take an int were changed. Everything else was kept.

AZero13 avatar Sep 17 '21 15:09 AZero13

@AtariDreams The definition of the ctype macros allows for the value -1 (EOF constant) and character values from 0 to 255 (the range of a typical unsigned char with 8-bit bytes).

The char data type is (explicitly per the C standards going back to K&R) undefined WRT signedness. The default on some platforms is signed char, and others unsigned char. If char is unsigned, then the "& 255" is not needed. But if char is signed, these ctype macros blow up spectacularly when confronted with UTF-8 text.

Our options are:

  1. Keep the "& 255"
  2. Write new versions of the macros that explicitly ignore values outside the range of 0 to 127 (although that will have some side-effects for some 8-bit charsets that the ctype macros might otherwise support)
  3. Write new versions of the macros that are UTF-8 aware and take a pointer instead of an integer

We are a week away from the first beta of CUPS 2.4.0. I do not want to create huge code churn before a beta for something that is clearly necessary from a "don't write code that will crash at random times" POV, so the "& 255" (option 1) will stay for CUPS 2.4.x.

Longer term I favor option 3 since CUPS uses UTF-8 internally, only converting to/from UTF-8 as needed for the command-line tools. And if you want to tackle that challenge for 2.5.x, please do!

Putting this PR in the "2.5" milestone for now...

michaelrsweet avatar Sep 17 '21 15:09 michaelrsweet

Hi @AtariDreams ,

have you had a time to look into changes which Mike'd requested?

I will put [WIP] into subject for now.

zdohnal avatar May 17 '22 05:05 zdohnal

Yes I have. I will get on it!

AZero13 avatar Jun 10 '22 13:06 AZero13

I have decided to split this change into multiple ones. Figured it would be for the best

AZero13 avatar Sep 12 '22 14:09 AZero13

@michaelrsweet I was wrong. You were right.

It turns out character literals are integers, not chars like in C++, so yeah the & 255 would make sense, even if we could remove them in practice and most likely get away with it since many of those functions do take integers anyway. I will revert them.

AZero13 avatar Oct 24 '22 13:10 AZero13