Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined behavior (left shift of negative value) when encoding an empty histogram #123

Open
TimWolla opened this issue Mar 18, 2024 · 0 comments

Comments

@TimWolla
Copy link

Consider the following program:

#include <stdlib.h>
#include "hdr/hdr_histogram.h"
#include "hdr/hdr_histogram_log.h"
#include "hdr/hdr_histogram_version.h"

int main() {
	struct hdr_histogram* histogram;
	char *result = NULL;

	hdr_init(1, 100, 1, &histogram);
	hdr_log_encode(histogram, &result);

	printf("%s\n", result);

	free(result);
	hdr_close(histogram);
}

Building the library with clang's address sanitizer via:

env CFLAGS="-g -O0 -fsanitize=undefined,address" LDFLAGS="-fsanitize=undefined,address" CC=clang CXX=clang++ cmake .

Then Compiling the test program using:

clang test.c -I/usr/local/include  -L/usr/local/lib -lhdr_histogram  -g -fsanitize=undefined,address

And executing ./a.out results in:

HdrHistogram_c/src/hdr_encoding.c:19:20: runtime error: left shift of negative value -1
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior HdrHistogram_c/src/hdr_encoding.c:19:20 in 
HISTFAAAABl4nJNpmSzMwMDAyAAB6HSK/QeoAABAagLe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant