blob: 44cd3dff26374f499ba029978905930dfe486b8e (
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
32
33
|
// 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, int withSeparator)
{
/* flawfinder: ignore. bound checks are done */
char buf[GOODWOLF_CTX_SIZ] = {0, 0, 0, 0, 0, 0, 0};
int len = 2;
buf[++len] = alpha_digits[num % 26];
num /= 26;
while(num > 0 && len < (GOODWOLF_CTX_SIZ - 1))
{
buf[++len] = alpha_digits[(num - 1) % 26];
num /= 26;
}
for(int i = 0; i < len; i++)
{
out[i] = buf[len - i];
}
if (withSeparator) {
out[len - 2] = ':';
out[len - 1] = ' ';
}
}
|