1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2025-04-14 17:32:55 -04:00

Main: Use assertions everywhere (closes #14)

This commit is contained in:
Alex Kotov 2022-05-25 02:01:51 +03:00
parent 8db18d3fee
commit 63ae527c4f
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
11 changed files with 135 additions and 10 deletions

View file

@ -2,6 +2,7 @@
#include "config.h"
#endif
#include <kernaux/assert.h>
#include <kernaux/cmdline.h>
#include <kernaux/libc.h>
@ -24,16 +25,12 @@ bool kernaux_cmdline(
const size_t argv_count_max,
const size_t buffer_size
) {
if (
cmdline == NULL ||
error_msg == NULL ||
argc == NULL ||
argv == NULL ||
argv_count_max == 0 ||
buffer_size == 0
) {
return false;
}
KERNAUX_NOTNULL_RETVAL(cmdline, false);
KERNAUX_NOTNULL_RETVAL(error_msg, false);
KERNAUX_NOTNULL_RETVAL(argc, false);
KERNAUX_NOTNULL_RETVAL(argv, false);
KERNAUX_ASSERT_RETVAL(argv_count_max > 0, false);
KERNAUX_ASSERT_RETVAL(buffer_size > 0, false);
memset(error_msg, '\0', KERNAUX_CMDLINE_ERROR_MSG_SIZE_MAX);
*argc = 0;

View file

@ -2,6 +2,7 @@
#include "config.h"
#endif
#include <kernaux/assert.h>
#include <kernaux/console.h>
#include <kernaux/libc.h>
@ -38,6 +39,8 @@ void kernaux_console_putc(const char c __attribute__((unused)))
void kernaux_console_print(const char *const s)
{
KERNAUX_NOTNULL_RETURN(s);
for (const char *c = s; *c; ++c) {
kernaux_console_putc(*c);
}
@ -46,6 +49,8 @@ void kernaux_console_print(const char *const s)
#ifdef WITH_PRINTF
void kernaux_console_printf(const char *format, ...)
{
KERNAUX_NOTNULL_RETURN(format);
va_list va;
va_start(va, format);
kernaux_vprintf(kernaux_console_printf_putc, NULL, format, va);
@ -55,12 +60,16 @@ void kernaux_console_printf(const char *format, ...)
void kernaux_console_puts(const char *const s)
{
KERNAUX_NOTNULL_RETURN(s);
kernaux_console_print(s);
kernaux_console_putc('\n');
}
void kernaux_console_write(const char *const data, const size_t size)
{
KERNAUX_NOTNULL_RETURN(data);
for (size_t i = 0; i < size; i++) {
kernaux_console_putc(data[i]);
}

View file

@ -2,11 +2,14 @@
#include "config.h"
#endif
#include <kernaux/assert.h>
#include <kernaux/elf.h>
bool KernAux_ELF_Header_is_valid(
const struct KernAux_ELF_Header *const header
) {
KERNAUX_NOTNULL_RETVAL(header, false);
if (!(
header->magic_0x7f == 0x7f &&
header->magic_E == 'E' &&

View file

@ -2,6 +2,7 @@
#include "config.h"
#endif
#include <kernaux/assert.h>
#include <kernaux/multiboot2.h>
#include <stddef.h>
@ -12,6 +13,8 @@ const struct KernAux_Multiboot2_HTagBase
const struct KernAux_Multiboot2_Header *const multiboot2_header,
const enum KernAux_Multiboot2_HTag tag_type
) {
KERNAUX_NOTNULL_RETVAL(multiboot2_header, NULL);
const struct KernAux_Multiboot2_HTagBase *tag_base =
(struct KernAux_Multiboot2_HTagBase*)
KERNAUX_MULTIBOOT2_DATA(multiboot2_header);
@ -35,10 +38,15 @@ const struct KernAux_Multiboot2_HTagBase
const enum KernAux_Multiboot2_HTag tag_type,
const struct KernAux_Multiboot2_HTagBase *const after_tag
) {
KERNAUX_NOTNULL_RETVAL(multiboot2_header, NULL);
KERNAUX_NOTNULL_RETVAL(after_tag, NULL);
const struct KernAux_Multiboot2_HTagBase *tag_base =
(struct KernAux_Multiboot2_HTagBase*)
KERNAUX_MULTIBOOT2_DATA(multiboot2_header);
KERNAUX_ASSERT_RETVAL(tag_base <= after_tag, NULL);
while (tag_base <
(struct KernAux_Multiboot2_HTagBase*)
((uint8_t*)multiboot2_header + multiboot2_header->total_size))

View file

@ -2,6 +2,7 @@
#include "config.h"
#endif
#include <kernaux/assert.h>
#include <kernaux/multiboot2.h>
#include <stdbool.h>
@ -11,6 +12,8 @@
bool KernAux_Multiboot2_Header_is_valid(
const struct KernAux_Multiboot2_Header *const multiboot2_header
) {
KERNAUX_NOTNULL_RETVAL(multiboot2_header, false);
if (multiboot2_header->magic != KERNAUX_MULTIBOOT2_HEADER_MAGIC) {
return false;
}
@ -83,6 +86,8 @@ bool KernAux_Multiboot2_Header_is_valid(
bool KernAux_Multiboot2_HTagBase_is_valid(
const struct KernAux_Multiboot2_HTagBase *tag_base
) {
KERNAUX_NOTNULL_RETVAL(tag_base, false);
switch (tag_base->type) {
case KERNAUX_MULTIBOOT2_HTAG_NONE:
return KernAux_Multiboot2_HTag_None_is_valid(
@ -136,6 +141,7 @@ bool KernAux_Multiboot2_HTagBase_is_valid(
bool KernAux_Multiboot2_HTag_None_is_valid(
const struct KernAux_Multiboot2_HTag_None *tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_HTAG_NONE &&
tag->base.size == 8
@ -145,6 +151,7 @@ bool KernAux_Multiboot2_HTag_None_is_valid(
bool KernAux_Multiboot2_HTag_InfoReq_is_valid(
const struct KernAux_Multiboot2_HTag_InfoReq *tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_HTAG_INFO_REQ &&
tag->base.size > 8 &&
@ -155,6 +162,7 @@ bool KernAux_Multiboot2_HTag_InfoReq_is_valid(
bool KernAux_Multiboot2_HTag_Addr_is_valid(
const struct KernAux_Multiboot2_HTag_Addr *tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_HTAG_ADDR &&
tag->base.size == 24
@ -164,6 +172,7 @@ bool KernAux_Multiboot2_HTag_Addr_is_valid(
bool KernAux_Multiboot2_HTag_EntryAddr_is_valid(
const struct KernAux_Multiboot2_HTag_EntryAddr *tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_HTAG_ENTRY_ADDR &&
tag->base.size == 12
@ -173,6 +182,7 @@ bool KernAux_Multiboot2_HTag_EntryAddr_is_valid(
bool KernAux_Multiboot2_HTag_Flags_is_valid(
const struct KernAux_Multiboot2_HTag_Flags *tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_HTAG_FLAGS &&
tag->base.size == 12
@ -182,6 +192,7 @@ bool KernAux_Multiboot2_HTag_Flags_is_valid(
bool KernAux_Multiboot2_HTag_Framebuffer_is_valid(
const struct KernAux_Multiboot2_HTag_Framebuffer *tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_HTAG_FRAMEBUFFER &&
tag->base.size == 20
@ -191,6 +202,7 @@ bool KernAux_Multiboot2_HTag_Framebuffer_is_valid(
bool KernAux_Multiboot2_HTag_ModuleAlign_is_valid(
const struct KernAux_Multiboot2_HTag_ModuleAlign *tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_HTAG_MODULE_ALIGN &&
tag->base.size == 8
@ -200,6 +212,7 @@ bool KernAux_Multiboot2_HTag_ModuleAlign_is_valid(
bool KernAux_Multiboot2_HTag_EFIBootServices_is_valid(
const struct KernAux_Multiboot2_HTag_EFIBootServices *tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_HTAG_EFI_BOOT_SERVICES &&
tag->base.size == 8
@ -209,6 +222,7 @@ bool KernAux_Multiboot2_HTag_EFIBootServices_is_valid(
bool KernAux_Multiboot2_HTag_EFII386EntryAddr_is_valid(
const struct KernAux_Multiboot2_HTag_EFII386EntryAddr *tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_HTAG_EFI_I386_ENTRY_ADDR &&
tag->base.size == 12
@ -218,6 +232,7 @@ bool KernAux_Multiboot2_HTag_EFII386EntryAddr_is_valid(
bool KernAux_Multiboot2_HTag_EFIAmd64EntryAddr_is_valid(
const struct KernAux_Multiboot2_HTag_EFIAmd64EntryAddr *tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_HTAG_EFI_AMD64_ENTRY_ADDR &&
tag->base.size == 12
@ -227,6 +242,8 @@ bool KernAux_Multiboot2_HTag_EFIAmd64EntryAddr_is_valid(
bool KernAux_Multiboot2_HTag_RelocatableHeader_is_valid(
const struct KernAux_Multiboot2_HTag_RelocatableHeader *tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
if (!(
tag->base.type == KERNAUX_MULTIBOOT2_HTAG_RELOCATABLE_HEADER &&
tag->base.size == 24 &&

View file

@ -2,6 +2,7 @@
#include "config.h"
#endif
#include <kernaux/assert.h>
#include <kernaux/multiboot2.h>
#include <stddef.h>
@ -11,6 +12,9 @@ void KernAux_Multiboot2_Header_print(
const struct KernAux_Multiboot2_Header *const multiboot2_header,
void (*const printf)(const char *format, ...)
) {
KERNAUX_NOTNULL_RETURN(multiboot2_header);
KERNAUX_NOTNULL_RETURN(printf);
printf("Multiboot 2 header\n");
printf(" magic: %u\n", multiboot2_header->magic);
printf(
@ -41,6 +45,9 @@ void KernAux_Multiboot2_HTagBase_print(
const struct KernAux_Multiboot2_HTagBase *const tag_base,
void (*const printf)(const char *format, ...)
) {
KERNAUX_NOTNULL_RETURN(tag_base);
KERNAUX_NOTNULL_RETURN(printf);
if (!KernAux_Multiboot2_HTagBase_is_valid(tag_base)) return;
printf("Multiboot 2 header tag\n");

View file

@ -2,6 +2,7 @@
#include "config.h"
#endif
#include <kernaux/assert.h>
#include <kernaux/multiboot2.h>
#include <stddef.h>
@ -12,6 +13,8 @@ const struct KernAux_Multiboot2_ITagBase
const struct KernAux_Multiboot2_Info *const multiboot2_info,
const enum KernAux_Multiboot2_ITag tag_type
) {
KERNAUX_NOTNULL_RETVAL(multiboot2_info, NULL);
const struct KernAux_Multiboot2_ITagBase *tag_base =
(struct KernAux_Multiboot2_ITagBase*)
KERNAUX_MULTIBOOT2_DATA(multiboot2_info);
@ -35,10 +38,15 @@ const struct KernAux_Multiboot2_ITagBase
const enum KernAux_Multiboot2_ITag tag_type,
const struct KernAux_Multiboot2_ITagBase *const after_tag
) {
KERNAUX_NOTNULL_RETVAL(multiboot2_info, NULL);
KERNAUX_NOTNULL_RETVAL(after_tag, NULL);
const struct KernAux_Multiboot2_ITagBase *tag_base =
(struct KernAux_Multiboot2_ITagBase*)
KERNAUX_MULTIBOOT2_DATA(multiboot2_info);
KERNAUX_ASSERT_RETVAL(tag_base <= after_tag, NULL);
while (tag_base <
(struct KernAux_Multiboot2_ITagBase*)
((uint8_t*)multiboot2_info + multiboot2_info->total_size))
@ -55,6 +63,8 @@ const struct KernAux_Multiboot2_ITagBase
const char *KernAux_Multiboot2_Info_boot_cmd_line(
const struct KernAux_Multiboot2_Info *const multiboot2_info
) {
KERNAUX_NOTNULL_RETVAL(multiboot2_info, NULL);
const struct KernAux_Multiboot2_ITag_BootCmdLine *const tag =
(struct KernAux_Multiboot2_ITag_BootCmdLine*)
KernAux_Multiboot2_Info_first_tag_with_type(

View file

@ -2,6 +2,7 @@
#include "config.h"
#endif
#include <kernaux/assert.h>
#include <kernaux/multiboot2.h>
#include <stdbool.h>
@ -11,6 +12,8 @@
bool KernAux_Multiboot2_Info_is_valid(
const struct KernAux_Multiboot2_Info *const multiboot2_info
) {
KERNAUX_NOTNULL_RETVAL(multiboot2_info, false);
if (multiboot2_info->total_size <
sizeof(struct KernAux_Multiboot2_Info) +
sizeof(struct KernAux_Multiboot2_ITag_None))
@ -64,6 +67,8 @@ bool KernAux_Multiboot2_Info_is_valid(
bool KernAux_Multiboot2_ITagBase_is_valid(
const struct KernAux_Multiboot2_ITagBase *const tag_base
) {
KERNAUX_NOTNULL_RETVAL(tag_base, false);
switch (tag_base->type) {
case KERNAUX_MULTIBOOT2_ITAG_NONE:
return KernAux_Multiboot2_ITag_None_is_valid(
@ -162,6 +167,7 @@ bool KernAux_Multiboot2_ITagBase_is_valid(
bool KernAux_Multiboot2_ITag_None_is_valid(
const struct KernAux_Multiboot2_ITag_None *const tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_ITAG_NONE &&
tag->base.size == 8
@ -171,6 +177,8 @@ bool KernAux_Multiboot2_ITag_None_is_valid(
bool KernAux_Multiboot2_ITag_BootCmdLine_is_valid(
const struct KernAux_Multiboot2_ITag_BootCmdLine *const tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
size_t index = 1;
for (
@ -190,6 +198,8 @@ bool KernAux_Multiboot2_ITag_BootCmdLine_is_valid(
bool KernAux_Multiboot2_ITag_BootLoaderName_is_valid(
const struct KernAux_Multiboot2_ITag_BootLoaderName *const tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
size_t index = 1;
for (
@ -209,6 +219,8 @@ bool KernAux_Multiboot2_ITag_BootLoaderName_is_valid(
bool KernAux_Multiboot2_ITag_Module_is_valid(
const struct KernAux_Multiboot2_ITag_Module *const tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
size_t index = 1;
for (
@ -229,6 +241,7 @@ bool KernAux_Multiboot2_ITag_Module_is_valid(
bool KernAux_Multiboot2_ITag_BasicMemoryInfo_is_valid(
const struct KernAux_Multiboot2_ITag_BasicMemoryInfo *const tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_ITAG_BASIC_MEMORY_INFO &&
tag->base.size == 16
@ -238,6 +251,7 @@ bool KernAux_Multiboot2_ITag_BasicMemoryInfo_is_valid(
bool KernAux_Multiboot2_ITag_BIOSBootDevice_is_valid(
const struct KernAux_Multiboot2_ITag_BIOSBootDevice *const tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_ITAG_BIOS_BOOT_DEVICE &&
tag->base.size == 20
@ -247,6 +261,7 @@ bool KernAux_Multiboot2_ITag_BIOSBootDevice_is_valid(
bool KernAux_Multiboot2_ITag_MemoryMap_is_valid(
const struct KernAux_Multiboot2_ITag_MemoryMap *const tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_ITAG_MEMORY_MAP &&
tag->base.size >= 16 &&
@ -259,6 +274,7 @@ bool KernAux_Multiboot2_ITag_MemoryMap_is_valid(
bool KernAux_Multiboot2_ITag_VBEInfo_is_valid(
const struct KernAux_Multiboot2_ITag_VBEInfo *const tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_ITAG_VBE_INFO &&
tag->base.size == 784
@ -268,6 +284,7 @@ bool KernAux_Multiboot2_ITag_VBEInfo_is_valid(
bool KernAux_Multiboot2_ITag_FramebufferInfo_is_valid(
const struct KernAux_Multiboot2_ITag_FramebufferInfo *const tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_ITAG_FRAMEBUFFER_INFO &&
tag->base.size >= 31
@ -277,6 +294,7 @@ bool KernAux_Multiboot2_ITag_FramebufferInfo_is_valid(
bool KernAux_Multiboot2_ITag_ELFSymbols_is_valid(
const struct KernAux_Multiboot2_ITag_ELFSymbols *const tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_ITAG_ELF_SYMBOLS &&
tag->base.size >= 16 &&
@ -290,6 +308,7 @@ bool KernAux_Multiboot2_ITag_ELFSymbols_is_valid(
bool KernAux_Multiboot2_ITag_APMTable_is_valid(
const struct KernAux_Multiboot2_ITag_APMTable *const tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_ITAG_APM_TABLE &&
tag->base.size == 28
@ -299,6 +318,7 @@ bool KernAux_Multiboot2_ITag_APMTable_is_valid(
bool KernAux_Multiboot2_ITag_EFI32bitSystemTablePtr_is_valid(
const struct KernAux_Multiboot2_ITag_EFI32bitSystemTablePtr *const tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_ITAG_EFI_32BIT_SYSTEM_TABLE_PTR &&
tag->base.size == 12
@ -308,6 +328,7 @@ bool KernAux_Multiboot2_ITag_EFI32bitSystemTablePtr_is_valid(
bool KernAux_Multiboot2_ITag_EFI64bitSystemTablePtr_is_valid(
const struct KernAux_Multiboot2_ITag_EFI64bitSystemTablePtr *const tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_ITAG_EFI_64BIT_SYSTEM_TABLE_PTR &&
tag->base.size == 16
@ -317,6 +338,7 @@ bool KernAux_Multiboot2_ITag_EFI64bitSystemTablePtr_is_valid(
bool KernAux_Multiboot2_ITag_SMBIOSTables_is_valid(
const struct KernAux_Multiboot2_ITag_SMBIOSTables *const tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_ITAG_SMBIOS_TABLES &&
tag->base.size >= 16
@ -326,6 +348,7 @@ bool KernAux_Multiboot2_ITag_SMBIOSTables_is_valid(
bool KernAux_Multiboot2_ITag_ACPIOldRSDP_is_valid(
const struct KernAux_Multiboot2_ITag_ACPIOldRSDP *const tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_ITAG_ACPI_OLD_RSDP &&
tag->base.size >= 8
@ -335,6 +358,7 @@ bool KernAux_Multiboot2_ITag_ACPIOldRSDP_is_valid(
bool KernAux_Multiboot2_ITag_ACPINewRSDP_is_valid(
const struct KernAux_Multiboot2_ITag_ACPINewRSDP *const tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_ITAG_ACPI_NEW_RSDP &&
tag->base.size >= 8
@ -344,6 +368,7 @@ bool KernAux_Multiboot2_ITag_ACPINewRSDP_is_valid(
bool KernAux_Multiboot2_ITag_NetworkingInfo_is_valid(
const struct KernAux_Multiboot2_ITag_NetworkingInfo *const tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_ITAG_NETWORKING_INFO &&
tag->base.size >= 8
@ -353,6 +378,7 @@ bool KernAux_Multiboot2_ITag_NetworkingInfo_is_valid(
bool KernAux_Multiboot2_ITag_EFIMemoryMap_is_valid(
const struct KernAux_Multiboot2_ITag_EFIMemoryMap *const tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_ITAG_EFI_MEMORY_MAP &&
tag->base.size >= 16
@ -362,6 +388,7 @@ bool KernAux_Multiboot2_ITag_EFIMemoryMap_is_valid(
bool KernAux_Multiboot2_ITag_EFIBootServicesNotTerminated_is_valid(
const struct KernAux_Multiboot2_ITag_EFIBootServicesNotTerminated *const tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type ==
KERNAUX_MULTIBOOT2_ITAG_EFI_BOOT_SERVICES_NOT_TERMINATED &&
@ -372,6 +399,7 @@ bool KernAux_Multiboot2_ITag_EFIBootServicesNotTerminated_is_valid(
bool KernAux_Multiboot2_ITag_EFI32bitImageHandlePtr_is_valid(
const struct KernAux_Multiboot2_ITag_EFI32bitImageHandlePtr *const tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_ITAG_EFI_32BIT_IMAGE_HANDLE_PTR &&
tag->base.size == 12
@ -381,6 +409,7 @@ bool KernAux_Multiboot2_ITag_EFI32bitImageHandlePtr_is_valid(
bool KernAux_Multiboot2_ITag_EFI64bitImageHandlePtr_is_valid(
const struct KernAux_Multiboot2_ITag_EFI64bitImageHandlePtr *const tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_ITAG_EFI_64BIT_IMAGE_HANDLE_PTR &&
tag->base.size == 16
@ -390,6 +419,7 @@ bool KernAux_Multiboot2_ITag_EFI64bitImageHandlePtr_is_valid(
bool KernAux_Multiboot2_ITag_ImageLoadBasePhysAddr_is_valid(
const struct KernAux_Multiboot2_ITag_ImageLoadBasePhysAddr *const tag
) {
KERNAUX_NOTNULL_RETVAL(tag, false);
return (
tag->base.type == KERNAUX_MULTIBOOT2_ITAG_IMAGE_LOAD_BASE_PHYS_ADDR &&
tag->base.size == 12

View file

@ -2,6 +2,7 @@
#include "config.h"
#endif
#include <kernaux/assert.h>
#include <kernaux/multiboot2.h>
#include <stddef.h>
@ -11,6 +12,9 @@ void KernAux_Multiboot2_Info_print(
const struct KernAux_Multiboot2_Info *const multiboot2_info,
void (*const printf)(const char *format, ...)
) {
KERNAUX_NOTNULL_RETURN(multiboot2_info);
KERNAUX_NOTNULL_RETURN(printf);
printf("Multiboot 2 info\n");
printf(" size: %u\n", multiboot2_info->total_size);
printf(" reserved1: %u\n", multiboot2_info->reserved1);
@ -35,6 +39,9 @@ void KernAux_Multiboot2_ITagBase_print(
const struct KernAux_Multiboot2_ITagBase *const tag_base,
void (*const printf)(const char *format, ...)
) {
KERNAUX_NOTNULL_RETURN(tag_base);
KERNAUX_NOTNULL_RETURN(printf);
if (!KernAux_Multiboot2_ITagBase_is_valid(tag_base)) return;
printf("Multiboot 2 info tag\n");
@ -219,6 +226,9 @@ void KernAux_Multiboot2_ITag_BootCmdLine_print(
const struct KernAux_Multiboot2_ITag_BootCmdLine *const tag,
void (*printf)(const char *format, ...)
) {
KERNAUX_NOTNULL_RETURN(tag);
KERNAUX_NOTNULL_RETURN(printf);
if (!KernAux_Multiboot2_ITag_BootCmdLine_is_valid(tag)) {
printf(" invalid!\n");
return;
@ -231,6 +241,9 @@ void KernAux_Multiboot2_ITag_BootLoaderName_print(
const struct KernAux_Multiboot2_ITag_BootLoaderName *const tag,
void (*printf)(const char *format, ...)
) {
KERNAUX_NOTNULL_RETURN(tag);
KERNAUX_NOTNULL_RETURN(printf);
if (!KernAux_Multiboot2_ITag_BootLoaderName_is_valid(tag)) {
printf(" invalid!\n");
return;
@ -243,6 +256,9 @@ void KernAux_Multiboot2_ITag_MemoryMap_print(
const struct KernAux_Multiboot2_ITag_MemoryMap *const tag,
void (*printf)(const char *format, ...)
) {
KERNAUX_NOTNULL_RETURN(tag);
KERNAUX_NOTNULL_RETURN(printf);
if (!KernAux_Multiboot2_ITag_MemoryMap_is_valid(tag)) {
printf(" invalid!\n");
return;
@ -274,6 +290,9 @@ void KernAux_Multiboot2_ITag_ELFSymbols_print(
const struct KernAux_Multiboot2_ITag_ELFSymbols *const tag,
void (*printf)(const char *format, ...)
) {
KERNAUX_NOTNULL_RETURN(tag);
KERNAUX_NOTNULL_RETURN(printf);
if (!KernAux_Multiboot2_ITag_ELFSymbols_is_valid(tag)) {
printf(" invalid!\n");
return;

View file

@ -10,6 +10,7 @@
#include "config.h"
#endif
#include <kernaux/assert.h>
#include <kernaux/libc.h>
#include <kernaux/printf.h>
@ -86,6 +87,9 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
int kernaux_printf(void (*out)(char character, void* arg), void* arg, const char* format, ...)
{
KERNAUX_NOTNULL_RETVAL(out, 0);
KERNAUX_NOTNULL_RETVAL(format, 0);
va_list va;
va_start(va, format);
const out_fct_wrap_type out_fct_wrap = { out, arg };
@ -96,12 +100,18 @@ int kernaux_printf(void (*out)(char character, void* arg), void* arg, const char
int kernaux_vprintf(void (*out)(char character, void* arg), void* arg, const char* format, va_list va)
{
KERNAUX_NOTNULL_RETVAL(out, 0);
KERNAUX_NOTNULL_RETVAL(format, 0);
const out_fct_wrap_type out_fct_wrap = { out, arg };
return _vsnprintf(_out_fct, (char*)(uintptr_t)&out_fct_wrap, (size_t)-1, format, va);
}
int kernaux_snprintf(char* buffer, size_t count, const char* format, ...)
{
KERNAUX_NOTNULL_RETVAL(buffer, 0);
KERNAUX_NOTNULL_RETVAL(format, 0);
va_list va;
va_start(va, format);
const int ret = _vsnprintf(_out_buffer, buffer, count, format, va);
@ -111,11 +121,17 @@ int kernaux_snprintf(char* buffer, size_t count, const char* format, ...)
int kernaux_vsnprintf(char* buffer, size_t count, const char* format, va_list va)
{
KERNAUX_NOTNULL_RETVAL(buffer, 0);
KERNAUX_NOTNULL_RETVAL(format, 0);
return _vsnprintf(_out_buffer, buffer, count, format, va);
}
int kernaux_sprintf(char* buffer, const char* format, ...)
{
KERNAUX_NOTNULL_RETVAL(buffer, 0);
KERNAUX_NOTNULL_RETVAL(format, 0);
va_list va;
va_start(va, format);
const int ret = _vsnprintf(_out_buffer, buffer, (size_t)-1, format, va);
@ -129,6 +145,8 @@ int kernaux_sprintf(char* buffer, const char* format, ...)
int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const char* format, va_list va)
{
KERNAUX_NOTNULL_RETVAL(format, 0);
unsigned int flags, width, precision, n;
size_t idx = 0u;

View file

@ -2,6 +2,7 @@
#include "config.h"
#endif
#include <kernaux/assert.h>
#include <kernaux/libc.h>
#include <kernaux/ntoa.h>
#include <kernaux/units.h>
@ -14,6 +15,9 @@ bool kernaux_units_human_raw(
char *const buffer,
const size_t buffer_size
) {
KERNAUX_NOTNULL_RETVAL(buffer, false);
KERNAUX_ASSERT_RETVAL(buffer_size > 0, false);
char tmp_buffer[TMP_BUFFER_SIZE];
char *tmp = tmp_buffer;
@ -51,6 +55,9 @@ bool kernaux_units_human_dec(
char *const buffer,
const size_t buffer_size
) {
KERNAUX_NOTNULL_RETVAL(buffer, false);
KERNAUX_ASSERT_RETVAL(buffer_size > 0, false);
char tmp_buffer[TMP_BUFFER_SIZE];
char *tmp = tmp_buffer;