libyaml icon indicating copy to clipboard operation
libyaml copied to clipboard

Patch yaml_scalar_event_initialize() to accept a proper size_t "length" argument

Open frickenate opened this issue 8 years ago • 1 comments

yaml_scalar_event_initialize() currently takes its length argument as an int, whereas the correct type is size_t. This results in an easily avoidable compiler warning about converting between unsigned and signed types.

The compromise here is to use 0 rather than -1 to request that the function take the strlen() of the value argument directly. I can't imagine a scenario where any code would pass an explicit 0 length while passing a non-empty value, and expect the function to respect the 0 length by not copying the passed value. The only "downside" being a technically unnecessary strlen() call for actual empty scalars.

Thoughts?

frickenate avatar Jan 19 '18 20:01 frickenate

Hi, I just came across this old PR. I think it makes lots of sense... string length should be defined as size_t. But this would be breaking API (especially the change from -1 to 0 for automatic length calculation). So we'd rather need to add a new yaml_scalar_event_initialize2() function instead.

slyon avatar Sep 04 '24 11:09 slyon