OpenPrinting / cups

OpenPrinting CUPS Sources
https://openprinting.github.io/cups
Apache License 2.0
1.05k stars 187 forks source link

cups/string.c: Add `_cups_snprintf()` #867

Closed zdohnal closed 8 months ago

zdohnal commented 8 months ago

Add the function which will remove the truncated UTF-8 multibyte characters.

zdohnal commented 8 months ago

@michaelrsweet ok, I made the function public + used _cups_safe_vsnprintf(), which does the job for logging - however it seems there was a bug in the function, which returned shorter string than the maximum possible, and returned higher number of written bytes than it actually wrote.

michaelrsweet commented 8 months ago

@michaelrsweet ok, I made the function public + used _cups_safe_vsnprintf(), which does the job for logging - however it seems there was a bug in the function, which returned shorter string than the maximum possible, and returned higher number of written bytes than it actually wrote.

Actually, that is the correct behavior. (v)snprintf return the number of bytes that would have been written, not the number of bytes written.

michaelrsweet commented 8 months ago

Fixes are in master.

zdohnal commented 8 months ago

No problem, I hope I helped in some way in the end.

michaelrsweet commented 8 months ago

@zdohnal For sure, aside from fixing the bug in this function, it also lead to related fixes in the cupsCopy/ConcatString. And we also promoted the old _cups_safe_snprintf function to API.