Summary Files Commits Branches @commit @diff @stats
path: root / fmt.c
blob: a88e8cb05031bec02d1e8e733bb99afd578e0ac8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// BadWolf: Minimalist and privacy-oriented WebKitGTK+ browser
// Copyright © 2019-2021 Badwolf Authors <https://hacktivis.me/projects/badwolf>
// SPDX-License-Identifier: BSD-3-Clause

#include "fmt.h"

/* flawfinder: ignore. `alpha_digits` is never modified */
static const char alpha_digits[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
void
fmt_context_id(uint64_t num, char *out)
{
	/* flawfinder: ignore. bound checks are done */
	char buf[BADWOLF_CTX_SIZ] = {0, 0, 0, 0, 0, 0, 0};
	int len                   = 0;

	buf[++len] = ' ';
	buf[++len] = ':';

	buf[++len] = alpha_digits[num % 26];
	num /= 26;
	while(num > 0 && len < (BADWOLF_CTX_SIZ - 1))
	{
		buf[++len] = alpha_digits[(num - 1) % 26];
		num /= 26;
	}

	for(int i = 0; i < len; i++)
	{
		out[i] = buf[len - i];
	}
}