Skip to content

Commit 84319ac

Browse files
Maintenance (#114)
1 parent cb83422 commit 84319ac

25 files changed

+138
-64
lines changed

.github/workflows/main.yml

+2-7
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,5 @@ jobs:
137137
- uses: actions/checkout@v2
138138
- name: dependencies
139139
run: sudo apt-get --yes install cppcheck
140-
- name: cppcheck source code
141-
# TODO: don't suppress "src/printf.c"
142-
run: cppcheck --quiet --error-exitcode=1 --std=c99 --enable=warning,style,performance,portability --suppress='*:src/printf.c' include/ src/ libc/
143-
- name: cppcheck examples
144-
run: cppcheck --quiet --error-exitcode=1 --std=c99 --enable=warning,style,performance,portability --suppress=duplicateExpression --suppress=staticStringCompare examples/
145-
- name: cppcheck tests
146-
run: cppcheck --quiet --error-exitcode=1 --std=c99 --enable=warning,style,performance,portability --suppress=unusedStructMember tests/
140+
- name: cppcheck
141+
run: cppcheck --quiet --error-exitcode=1 --std=c99 --enable=warning,style,performance,portability --inline-suppr examples/ include/ libc/ src/ tests/

CONTRIBUTING.md

+7
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ Avoid stupid errors with:
6262
* Default case in switch statements
6363
* Braces (curly brackets) around code blocks
6464

65+
### Things to review periodically
66+
67+
* `git grep -i fixme`
68+
* `git grep -i todo`
69+
* `git grep -i cppcheck-suppress`
70+
* `git grep -i rubocop:disable`
71+
6572

6673

6774
C language

ChangeLog

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2022-12-01 Alex Kotov <kotovalexarian@gmail.com>
2+
3+
* src/printf.c: Fix a bug with too big float precision
4+
15
2022-11-30 Alex Kotov <kotovalexarian@gmail.com>
26

37
* configure.ac: Fix CFLAGS setting
@@ -10,6 +14,10 @@
1014
"KERNAUX_RETURNS_TWICE", "KERNAUX_ASM"
1115
* include/kernaux/printf_fmt.h: Make stable
1216

17+
2022-11-27 Alex Kotov <kotovalexarian@gmail.com>
18+
19+
* src/free_list.c: Bug fixed
20+
1321
2022-11-26 Alex Kotov <kotovalexarian@gmail.com>
1422

1523
libkernaux 0.5.0 released

Makefile.am

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ lib_LTLIBRARIES = libkernaux.la
3030
libkernaux_la_LIBADD =
3131
libkernaux_la_SOURCES = \
3232
src/assert.c \
33-
src/libc.h \
3433
src/generic/malloc.c \
3534
src/generic/mutex.c
3635

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ API
3535
### Headers
3636

3737
We use [semantic versioning](https://semver.org) for stable APIs. Stable APIs
38-
can only change when major version number is increased (or minor while major is
38+
may only change when major version number is increased (or minor while major is
3939
zero). Work-in-progress APIs can change at any time.
4040

4141
* Basic features

bindings/mruby/src/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void mrb_mruby_kernaux_gem_init(mrb_state *const mrb)
3737
#endif // KERNAUX_VERSION_WITH_PRINTF
3838
}
3939

40-
void current_mrb_start(mrb_state *mrb)
40+
void current_mrb_start(mrb_state *const mrb)
4141
{
4242
mrb_assert(mrb_stack_count < MRB_STACK_SIZE - 1);
4343
mrb_assert(mrb_stack[mrb_stack_count] == NULL);
@@ -46,7 +46,7 @@ void current_mrb_start(mrb_state *mrb)
4646
mrb_stack[mrb_stack_count++] = mrb;
4747
}
4848

49-
void current_mrb_finish(mrb_state *mrb)
49+
void current_mrb_finish(mrb_state *const mrb)
5050
{
5151
mrb_assert(mrb_stack_count > 0);
5252
mrb_assert(mrb_stack[mrb_stack_count - 1] != NULL);

common/printf.yml

+37-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,43 @@
8989
- result: '1.200000'
9090
args: [['%f', 1.2]]
9191
float: true
92-
9392
- result: '123.456789'
9493
args: [['%f', 123.456789]]
9594
float: true
95+
96+
- result: '0.01234568'
97+
args: [['%.8f', 0.0123456789012345678901234567890123456789]]
98+
float: true
99+
- result: '0.012345679'
100+
args: [['%.9f', 0.0123456789012345678901234567890123456789]]
101+
float: true
102+
# Actual precision is no more than 9
103+
- result: '0.0123456790'
104+
args: [['%.10f', 0.0123456789012345678901234567890123456789]]
105+
float: true
106+
- result: '0.01234567900'
107+
args: [['%.11f', 0.0123456789012345678901234567890123456789]]
108+
float: true
109+
- result: '0.012345679000'
110+
args: [['%.12f', 0.0123456789012345678901234567890123456789]]
111+
float: true
112+
- result: '0.012345679000000000000000000000'
113+
args: [['%.30f', 0.0123456789012345678901234567890123456789]]
114+
float: true
115+
# Actual length is no more than 32
116+
- result: '0.012345679000000000000000000000'
117+
args: [['%.31f', 0.0123456789012345678901234567890123456789]]
118+
float: true
119+
- result: '0.012345679000000000000000000000'
120+
args: [['%.32f', 0.0123456789012345678901234567890123456789]]
121+
float: true
122+
# Actual length is no more than 32
123+
- result: '10.01234567900000000000000000000'
124+
args: [['%.32f', 10.0123456789012345678901234567890123456789]]
125+
float: true
126+
- result: '100.0123456790000000000000000000'
127+
args: [['%.32f', 100.0123456789012345678901234567890123456789]]
128+
float: true
129+
- result: '1000.012345679000000000000000000'
130+
args: [['%.32f', 1000.0123456789012345678901234567890123456789]]
131+
float: true

examples/assert.c

+3
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,23 @@ int main()
2525
{
2626
kernaux_assert_cb = assert_cb;
2727

28+
// cppcheck-suppress duplicateExpression
2829
KERNAUX_ASSERT(1 == 1);
2930

3031
assert(count == 0);
3132
assert(last_file == NULL);
3233
assert(last_line == 0);
3334
assert(last_str == NULL);
3435

36+
// cppcheck-suppress duplicateExpression
3537
KERNAUX_ASSERT(1 != 1);
3638

3739
assert(count == 1);
3840
assert(strcmp(last_file, __FILE__) == 0);
3941
assert(last_line == __LINE__ - 4);
4042
assert(strcmp(last_str, "1 != 1") == 0);
4143

44+
// cppcheck-suppress staticStringCompare
4245
KERNAUX_ASSERT(strcmp("qwe", "rty") == 0);
4346

4447
assert(count == 2);

examples/generic_malloc.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ static void *MyMalloc_realloc(void *malloc, void *ptr, size_t size);
3535

3636
struct MyMalloc MyMalloc_create()
3737
{
38-
struct MyMalloc my_malloc;
39-
my_malloc.malloc.calloc = MyMalloc_calloc;
40-
my_malloc.malloc.free = MyMalloc_free;
41-
my_malloc.malloc.malloc = MyMalloc_malloc;
42-
my_malloc.malloc.realloc = MyMalloc_realloc;
43-
return my_malloc;
38+
return (struct MyMalloc){
39+
.malloc = {
40+
.calloc = MyMalloc_calloc,
41+
.free = MyMalloc_free,
42+
.malloc = MyMalloc_malloc,
43+
.realloc = MyMalloc_realloc,
44+
},
45+
};
4446
}
4547

4648
void *MyMalloc_calloc(void *const malloc, const size_t nmemb, const size_t size)

examples/generic_mutex.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ static void MyMutex_unlock(void *mutex);
3535

3636
struct MyMutex MyMutex_create()
3737
{
38-
struct MyMutex my_mutex;
39-
my_mutex.mutex.lock = MyMutex_lock;
40-
my_mutex.mutex.unlock = MyMutex_unlock;
38+
struct MyMutex my_mutex = {
39+
.mutex = {
40+
.lock = MyMutex_lock,
41+
.unlock = MyMutex_unlock,
42+
},
43+
};
4144
if (pthread_mutex_init(&my_mutex.pthread_mutex, NULL) != 0) abort();
4245
return my_mutex;
4346
}

examples/macro_container_of.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <kernaux/macro.h>
22

33
#include <assert.h>
4+
#include <string.h>
45

56
struct Foo {
67
const char *hello;
@@ -29,5 +30,6 @@ void example_main()
2930

3031
assert(bar_ptr->a == 143);
3132
assert(bar_ptr->b == 820794098);
33+
assert(strcmp(bar_ptr->foo.hello, "Hello, World!") == 0);
3234
assert(bar_ptr->c == 10981);
3335
}

examples/multiboot2_header_macro.c

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ static const struct {
1111
// of type "KernAux_Multiboot2_HTag_InfoReq"
1212
// when the number of requested information
1313
// tag types is even (n % 2 == 0).
14+
//
15+
// cppcheck-suppress unknownMacro
1416
KERNAUX_MULTIBOOT2_HFIELDS_INFO_REQ_EVEN(
1517
// This is the name of the structure field.
1618
tag_info_req_even,
@@ -22,6 +24,8 @@ static const struct {
2224
// of type "KernAux_Multiboot2_HTag_InfoReq"
2325
// when the number of requested information
2426
// tag types is odd (n % 2 == 1).
27+
//
28+
// cppcheck-suppress unknownMacro
2529
KERNAUX_MULTIBOOT2_HFIELDS_INFO_REQ_ODD(
2630
// This is the name of the structure field.
2731
tag_info_req_odd,
@@ -34,6 +38,8 @@ static const struct {
3438
_align1
3539
)
3640
// This macro may be used for all other header tag types.
41+
//
42+
// cppcheck-suppress unknownMacro
3743
KERNAUX_MULTIBOOT2_HFIELDS_COMMON(
3844
// This is the name of the structure field.
3945
tag_none,

examples/printf_file.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ static const char *const data = "foobar";
1212
static char buffer[BUFFER_SIZE];
1313
static size_t buffer_index = 0;
1414

15-
static void my_putchar(const char chr, void *arg)
15+
static void my_putchar(const char chr, void *const arg)
1616
{
1717
assert(arg == data);
1818
if (buffer_index >= BUFFER_SIZE) abort();

examples/printf_file_va.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ static const char *const data = "foobar";
1212
static char buffer[BUFFER_SIZE];
1313
static size_t buffer_index = 0;
1414

15-
static void my_putchar(const char chr, void *arg)
15+
static void my_putchar(const char chr, void *const arg)
1616
{
1717
assert(arg == data);
1818
if (buffer_index >= BUFFER_SIZE) abort();

include/kernaux/drivers/shutdown.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ extern "C" {
77

88
#include <kernaux/macro.h>
99

10-
KERNAUX_NORETURN
11-
void kernaux_drivers_shutdown_halt();
12-
void kernaux_drivers_shutdown_poweroff();
10+
KERNAUX_NORETURN void kernaux_drivers_shutdown_halt();
11+
KERNAUX_NORETURN void kernaux_drivers_shutdown_poweroff();
1312

1413
#ifdef __cplusplus
1514
}

include/kernaux/multiboot2.h.in

+7-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ extern "C" {
1515
#define KERNAUX_MULTIBOOT2_HEADER_MAGIC 0xe85250d6
1616
#define KERNAUX_MULTIBOOT2_INFO_MAGIC 0x36d76289
1717

18-
#define KERNAUX_MULTIBOOT2_HEADER_ALIGN 4
18+
// @see https://www.gnu.org/software/grub/manual/multiboot2/multiboot.html#OS-image-format
19+
#define KERNAUX_MULTIBOOT2_HEADER_ALIGN 8
20+
// @see https://www.gnu.org/software/grub/manual/multiboot2/multiboot.html#Basic-tags-structure
21+
#define KERNAUX_MULTIBOOT2_INFO_ALIGN 8
22+
// @see https://www.gnu.org/software/grub/manual/multiboot2/multiboot.html#Header-tags
23+
// @see https://www.gnu.org/software/grub/manual/multiboot2/multiboot.html#Basic-tags-structure
24+
#define KERNAUX_MULTIBOOT2_TAG_ALIGN 8
1925

2026
#define KERNAUX_MULTIBOOT2_HEADER_CHECKSUM(arch, total_size) \
2127
((uint32_t)(-( \
@@ -26,8 +32,6 @@ extern "C" {
2632

2733
#define KERNAUX_MULTIBOOT2_DATA(ptr) (((uint8_t*)(ptr)) + sizeof(*(ptr)))
2834

29-
#define KERNAUX_MULTIBOOT2_TAG_ALIGN 8
30-
3135
#define KERNAUX_MULTIBOOT2_HTAG_NEXT(tag_base) \
3236
((struct KernAux_Multiboot2_HTagBase*)KERNAUX_MULTIBOOT2_TAG_NEXT(tag_base))
3337
#define KERNAUX_MULTIBOOT2_ITAG_NEXT(tag_base) \

src/libc.h

-18
This file was deleted.

src/ntoa.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ char *kernaux_utoa(uint64_t value, char *buffer, int base, const char *prefix)
4747
char *pos = buffer;
4848
if (value == 0) *(pos++) = '0';
4949
while (value > 0) {
50+
// cppcheck-suppress zerodivcond
5051
const char mod = value % base;
5152
*(pos++) = mod < 10 ? mod + '0' : mod - 10 + alpha;
52-
value /= base;
53+
// cppcheck-suppress zerodivcond
54+
value /= base;
5355
}
5456
char *const result = pos;
5557
*(pos--) = '\0';

src/pfa.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <kernaux/macro.h>
77
#include <kernaux/pfa.h>
88

9-
#include "libc.h"
9+
#include <string.h>
1010

1111
#define PAGE_INDEX(page_addr) ((page_addr) / KERNAUX_PFA_PAGE_SIZE)
1212

0 commit comments

Comments
 (0)