The FC_GetBounds function formats the passed text into fc_buffer, then passes that buffer to the FC_GetWidth and FC_GetHeight functions. These in turn perform another formatting of text into the same fc_buffer destination.
Effectively, it is performing the following action inside FC_GetWidth and FC_GetHeight:
snprintf(fc_buffer, "%s", fc_buffer)
This is undefined behavior. On many platforms, it works fine. However, on Ubuntu 18.04 with GCC version 7.3.0, this causes fc_buffer to receive the empty string no matter what the input is. Since the string is now empty, the resulting width of the string is always zero.
The fix would be to use two different buffers, or make a function that computes the width and height on the string directly without formatting it.
Worked around the problem by using FC_GetWidth and FC_GetHeight directly.
Thanks for the catch. I used the first option, but the second is a better solution to avoid dynamic allocations (create function that assumes non-format strings).
The FC_GetBounds function formats the passed text into
fc_buffer
, then passes that buffer to theFC_GetWidth
andFC_GetHeight
functions. These in turn perform another formatting of text into the samefc_buffer
destination.Effectively, it is performing the following action inside
FC_GetWidth
andFC_GetHeight
:snprintf(fc_buffer, "%s", fc_buffer)
This is undefined behavior. On many platforms, it works fine. However, on Ubuntu 18.04 with GCC version 7.3.0, this causes
fc_buffer
to receive the empty string no matter what the input is. Since the string is now empty, the resulting width of the string is always zero.The fix would be to use two different buffers, or make a function that computes the width and height on the string directly without formatting it.
Worked around the problem by using
FC_GetWidth
andFC_GetHeight
directly.