rxi/sfd

make_filter_str bug (solution proposed)

Opened this issue · 0 comments

Hey,
Thank you for a simple and useful library!

However, there was a (supposedly) bug that I had to fix for the filter.

The function make_filter_str didn't append the filters to the filter name (i.e. result should be "Executables *.exe;" but it was "Executables")

This is because the byte after 's' in "Executables" was null-terminated ('\0') and when "Executables" is printed to the buffer with this line:

n += sprintf(buf + n, "%s", name) + 1;

n is advanced with the bytes in "Executables" plus the next byte which is '\0'. This means that when the filters are printed to the buffer with the line:

n += sprintf(buf + n, "%s;", b);

They are placed after the null-termination ('\0').

My solution to this is to instead of advancing the pointer offset (n) by 1 after printing the name, you should print the name with a a space byte afterwards like this:

n += sprintf(buf + n, "%s ", name);

instead of the line mentioned above:

n += sprintf(buf + n, "%s", name) + 1;

This will make sure that the byte after the name bytes is 32 (space) and that the filters will be appended before the null termination.

It might be worth mentioning that I am compiling this with a C++ compiler so there might be a slight variation in results.