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

Add Compile-time checking of LOG arguments #4

Open
geekymoose opened this issue Nov 25, 2017 · 0 comments
Open

Add Compile-time checking of LOG arguments #4

geekymoose opened this issue Nov 25, 2017 · 0 comments

Comments

@geekymoose
Copy link
Owner

geekymoose commented Nov 25, 2017

Description

Logger use printf like format with variables.
For instance LOG_DEBUG(0, "Variable a = %d", varA) with varA an integer.
In case of user gives wrong format (For instance %s), a segfault is generated.

Issue

No nice error message displayed!
It is really hard from the end user point of view to understand the error comes from its log format. (And anyway, logger should be able to segfault the program like this.)

Compiler-time format checking is required. (For the vsnprintf call)

Reproduce the error

Run this beautiful piece of code

#include <logger/elephant.h>

int main(int argc, char** argv) {
    elephant::init();

    int counter = 20;
    LOG_DEBUG(0, "Counter %s", counter); // %s should be %d -> segfault!
    return 0;
}

To run, you can use
g++ -g -Wall -I/path/to/logger/includes main.cpp /path/to/elephantlib/libelephant.a -pthread -lstdc++fs
(lstdc++fs is for the required experimental/filesystem)

Last words

Little elephant wish you good luck!

Your code:
logerror

The (only..) message you get
segfault

@geekymoose geekymoose added the bug label Nov 25, 2017
@geekymoose geekymoose changed the title Wrong format in LOG generated error impossible to understand by end user Add Compile-time checking of LOG arguments Nov 26, 2017
@geekymoose geekymoose changed the title Add Compile-time checking of LOG arguments Add Compile-time checking for LOG arguments Nov 26, 2017
@geekymoose geekymoose changed the title Add Compile-time checking for LOG arguments Add Compile-time checking of LOG arguments Nov 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant