logo

badwolf

minimalist and privacy-oriented web browser based on WebKitGTK git clone https://hacktivis.me/git/badwolf.git

fmt.c (787B)


  1. // BadWolf: Minimalist and privacy-oriented WebKitGTK+ browser
  2. // SPDX-FileCopyrightText: 2019-2022 Badwolf Authors <https://hacktivis.me/projects/badwolf>
  3. // SPDX-License-Identifier: BSD-3-Clause
  4. #include "fmt.h"
  5. /* flawfinder: ignore. `alpha_digits` is never modified */
  6. static const char alpha_digits[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  7. void
  8. fmt_context_id(uint64_t num, char *out)
  9. {
  10. /* flawfinder: ignore. bound checks are done */
  11. char buf[BADWOLF_CTX_SIZ] = {0, 0, 0, 0, 0, 0, 0};
  12. int len = 0;
  13. buf[++len] = ' ';
  14. buf[++len] = ':';
  15. buf[++len] = alpha_digits[num % 26];
  16. num /= 26;
  17. while(num > 0 && len < (BADWOLF_CTX_SIZ - 1))
  18. {
  19. buf[++len] = alpha_digits[(num - 1) % 26];
  20. num /= 26;
  21. }
  22. for(int i = 0; i < len; i++)
  23. {
  24. out[i] = buf[len - i];
  25. }
  26. }