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

Bug in print_string_ptr() increment is 4 instead of 5 #862

Closed
mbeynon opened this issue May 29, 2024 · 2 comments
Closed

Bug in print_string_ptr() increment is 4 instead of 5 #862

mbeynon opened this issue May 29, 2024 · 2 comments

Comments

@mbeynon
Copy link

mbeynon commented May 29, 2024

The sprintf() call before this uses a format string of "ux", which is a u followed by 4 hex chars. This means it always prints 5 chars. The increment on this line only increments by 4 instead of 5, which seems to be a bug by inspection.

cJSON/cJSON.c

Line 1021 in 3249730

output_pointer = 4;

Thank you

@PeterAlfredLee
Copy link
Contributor

PeterAlfredLee commented May 29, 2024

Well, I do not think this is a bug.
Please notice there is a input_pointer in the for loop here :
https://github.com/DaveGamble/cJSON/blob/master/cJSON.c#L984

    for (input_pointer = input; *input_pointer != '\0'; (void)input_pointer  , output_pointer  )

Which means it will be 4 1 = 5 chars.

@mbeynon
Copy link
Author

mbeynon commented May 29, 2024

Ah yes, you are correct. That code only needs to increment output_pointer for anything beyond the single character that the loop already handles.

My mistake ... sorry for the noise.

@mbeynon mbeynon closed this as completed May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants