Skip to content

[MSAN] Does not detect uninitialized large (800+ bytes) structs across function calls #169108

@JustLinuxUser

Description

@JustLinuxUser
// -Wall -Wextra -Wpedantic -fsanitize=memory -g -fno-inline-functions
#include <stddef.h>
#include <stdio.h>
#include <sys/types.h>

typedef struct s_large_struct
{
	char arr[800]; // With 799 the error is detected
	char other;
}	t_large_struct;

void	use_uninit(t_large_struct s)
{
	printf("el: %i\n", s.other);
}

int	main(void)
{
	t_large_struct	s;
	use_uninit(s);
}

Godbolt

For some reason msan stops tracking uninitialized structs across function calls when the function inlining is disabled, and the struct is larger then 800 bytes.

Here is a version that can be compiled with no warnings

#include <stdio.h>

typedef struct s_large_struct
{
	char other;
	char arr[800]; // With 799 the error is detected
}	t_large_struct;

void	use_uninit(t_large_struct s)
{
	printf("el: %i\n", s.other);
}

t_large_struct get_uninit_struct(void) {
	t_large_struct ret;
	ret.arr[0] = 0;
	return ret;
}

int	main(void)
{
	t_large_struct	s = get_uninit_struct();
	use_uninit(s);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions