Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle systems where char is unsigned. #53

Merged
merged 1 commit into from Jul 30, 2018

Conversation

@QuLogic
Copy link
Contributor

@QuLogic QuLogic commented Jul 25, 2018

The code currently assumes that char is signed and that values>127 mean checking for < 0. This is not guaranteed by the spec, and on systems where char is unsigned, these checks fail.

As an example, see this build which fails on aarch64, armv7hl, ppc64(le) and s390x, whereas this build with the attached change is now passing.

Copy link
Contributor Author

@QuLogic QuLogic left a comment

Just a check for something I might have misunderstood.

@@ -613,8 +613,8 @@ struct FANSI_state FANSI_read_next(struct FANSI_state state) {

// Normal ASCII characters
if(chr_val >= 0x20 && chr_val < 0x7F) state = read_ascii(state);

This comment has been minimized.

@QuLogic

QuLogic Jul 25, 2018
Author Contributor

PS, is there an off-by-one here? Should this be <= 0x7F?

This comment has been minimized.

@brodieG

brodieG Jul 25, 2018
Owner

This is intentional. The 'del' character is treated the same way as 0x00 - 0x20 (zero width). I don't know why the creators of ASCII threw it at the end of the list instead of the C0 section at front (I'm sure there is a good historical reason for this).

@@ -116,7 +116,7 @@ struct FANSI_csi_pos FANSI_find_esc(const char * x, int what) {
int found_this = 0;

// If not normal ASCII or UTF8, examine whether we need to found
if(!((x_val > 31 && x_val < 127) || x_val < 0)) {
if(!((x_val > 31 && x_val < 127) || x_val < 0 || x_val > 127)) {

This comment has been minimized.

@QuLogic

QuLogic Jul 25, 2018
Author Contributor

and also here with <= 127?

I'm 50/50 on this one because it seems a bit weird that 127 is left out.

@brodieG
Copy link
Owner

@brodieG brodieG commented Jul 25, 2018

I certainly had not considered that there are systems where by default char is unsigned, or TBH even realized that the standard does not specify anything as to what char is, so there are probably problems with that here. I'm planning on making some updates to this package this week so I'll review your pull request then. I fear there may be other problems elsewhere.

Please note that I'd like the pull requests made against the development branch, not the master branch (as per the contribution guidelines).

Thank you for taking the time to put together a PR, and thanks for teaching me something here.

@QuLogic QuLogic changed the base branch from master to development Jul 26, 2018
@QuLogic
Copy link
Contributor Author

@QuLogic QuLogic commented Jul 26, 2018

Easily done, but the development branch is behind master, so that's why I did not target it originally.

The code currently assumes that char is signed and that values>127 mean
checking for < 0. This is not guaranteed by the spec, and on systems
where char is unsigned, these checks fail.
@QuLogic QuLogic force-pushed the QuLogic:unsigned-char branch from ec3f270 to a4bc0a2 Jul 26, 2018
@codecov-io
Copy link

@codecov-io codecov-io commented Jul 26, 2018

Codecov Report

Merging #53 into development will decrease coverage by 6.63%.
The diff coverage is 100%.

Impacted file tree graph

@@               Coverage Diff               @@
##           development      #53      +/-   ##
===============================================
- Coverage          100%   93.36%   -6.64%     
===============================================
  Files               24       24              
  Lines             2044     2035       -9     
===============================================
- Hits              2044     1900     -144     
- Misses               0      135     +135
Impacted Files Coverage Δ
src/tohtml.c 100% <ø> (ø) ⬆️
src/utils.c 100% <100%> (ø) ⬆️
src/utf8.c 100% <100%> (ø) ⬆️
src/read.c 100% <100%> (ø) ⬆️
R/tohtml.R 33.33% <0%> (-66.67%) ⬇️
R/strip.R 38.46% <0%> (-61.54%) ⬇️
R/has.R 42.85% <0%> (-57.15%) ⬇️
R/nchar.R 45.71% <0%> (-54.29%) ⬇️
R/strwrap.R 56.98% <0%> (-43.02%) ⬇️
R/strtrim.R 76.08% <0%> (-23.92%) ⬇️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 076145c...a4bc0a2. Read the comment docs.

@brodieG brodieG merged commit 8d9bab9 into brodieG:development Jul 30, 2018
1 check failed
1 check failed
continuous-integration/travis-ci/pr The Travis CI build could not complete due to an error
Details
@QuLogic QuLogic deleted the QuLogic:unsigned-char branch Jul 30, 2018
@brodieG
Copy link
Owner

@brodieG brodieG commented Jul 30, 2018

Thanks for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.