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

replace sprintf in H3Index.c h3ToString() #6

Open
2 tasks
dcooley opened this issue Jul 10, 2023 · 2 comments
Open
2 tasks

replace sprintf in H3Index.c h3ToString() #6

dcooley opened this issue Jul 10, 2023 · 2 comments

Comments

@dcooley
Copy link
Contributor

dcooley commented Jul 10, 2023

H3Index.c uses sprintf, but this won't pass R Checks (as of R 4.3)

checking compiled code ... WARNING
  Fileh3lib/libs/h3lib.so:
    Found_sprintf’, possibly fromsprintf’ (C)
      Object:h3Index.oCompiled code should not call entry points which might terminate R nor
  write to stdout/stderr instead of to the console, nor use Fortran I/O
  nor system RNGs nor [v]sprintf.

Reference - https://www.tidyverse.org/blog/2023/03/cran-checks-compiled-code/#warning-regarding-the-use-of-codesprintfcode-in-cc

The solution is to use snprintf()

But this means we need to update the H3 source code directly.

  • Make a PR into H3?
  • Update it locally, plus our update script?
@dcooley dcooley changed the title h3 uses sprintf replace sprintf in H3Index.c h3ToString() Jul 10, 2023
@dcooley
Copy link
Contributor Author

dcooley commented Jul 11, 2023

linked issue - uber/h3#774

@dcooley
Copy link
Contributor Author

dcooley commented Jul 13, 2023

I think our best option is to

  • update h3Index.c to fail
    //sprintf(str, "%" PRIx64, h);
    //return E_SUCCESS;
    return E_FAILED;
  • remove h3ToString from init.c
  • Implement our own version in h3r
SEXP h3ToSexpString(H3Index h3) {
  char str[17];
  //h3ToString(h3, str, sizeof(str));
  int res = snprintf(str, sizeof(str), "%" PRIx64, h3);
  return Rf_mkChar(str);
}

dcooley pushed a commit that referenced this issue Jul 13, 2023
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

1 participant