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

libgis: G_vasprintf bug fix #3650

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

HuidaeCho
Copy link
Member

@HuidaeCho HuidaeCho commented Apr 23, 2024

This PR fixes a G_vasprintf bug for #else of #ifdef HAVE_ASPRINTF.

From the man page of vsnprintf():

   Upon successful return, these functions return  the  number  of  bytes
   printed (excluding the null byte used to end output to strings).

   The  functions  snprintf() and vsnprintf() do not write more than size
   bytes (including the terminating null byte ('\0')).  If the output was
   truncated due to this limit, then the return value is  the  number  of
   characters (excluding the terminating null byte) which would have been
   written to the final string if enough space had been available.  Thus,
   a  return  value  of size or more means that the output was truncated.
  1. We don't need to keep doubling size *= 2 because count is already the full length without \0 if it's greater than or equal to size.
  2. ap cannot be reused in a for loop. It needs to be copied before its first use so we can use it again.

@github-actions github-actions bot added C Related code is in C libraries labels Apr 23, 2024
@HuidaeCho HuidaeCho added the bug Something isn't working label Apr 23, 2024
@echoix echoix added this to the 8.4.0 milestone Apr 23, 2024
@HuidaeCho HuidaeCho self-assigned this May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working C Related code is in C libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants