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

Various NULL pointer warnings with '%s' format in libaccfg.c when compiling with clearlinux build options #56

Open
ColinIanKing opened this issue Mar 1, 2024 · 0 comments

Comments

@ColinIanKing
Copy link
Contributor

Hi,

When building idxd-config on ClearLinux I noticed some warnings when using gcc-13

Tool chain: gcc 13.2.1
The build flags that trigger this are: CC=gcc-13 CFLAGS="-Wformat-security -O3" ./configure

seems that the -O3 flag triggers more code analysis and triggers the warnings

libaccfg.c: In function 'accfg_group_set_traffic_class_a':
libaccfg.c:1736:48: warning: '%s' directive argument is null [-Wformat-overflow=]
 1736 |                 rc = sprintf(group->group_buf, "%s/%s", \
      |                                                ^~~~~~~
libaccfg.c:1762:1: note: in expansion of macro 'accfg_group_set_field'
 1762 | accfg_group_set_field(group, val, traffic_class_a)
      | ^~~~~~~~~~~~~~~~~~~~~
libaccfg.c:1736:52: note: format string is defined here
 1736 |                 rc = sprintf(group->group_buf, "%s/%s", \
      |                                                    ^~
libaccfg.c: In function 'accfg_group_set_traffic_class_b':
libaccfg.c:1736:48: warning: '%s' directive argument is null [-Wformat-overflow=]
 1736 |                 rc = sprintf(group->group_buf, "%s/%s", \
      |                                                ^~~~~~~
libaccfg.c:1763:1: note: in expansion of macro 'accfg_group_set_field'
 1763 | accfg_group_set_field(group, val, traffic_class_b)
      | ^~~~~~~~~~~~~~~~~~~~~
libaccfg.c:1736:52: note: format string is defined here
 1736 |                 rc = sprintf(group->group_buf, "%s/%s", \
      |                                                    ^~
libaccfg.c: In function 'accfg_group_set_desc_progress_limit':
libaccfg.c:1736:48: warning: '%s' directive argument is null [-Wformat-overflow=]
 1736 |                 rc = sprintf(group->group_buf, "%s/%s", \
      |                                                ^~~~~~~
libaccfg.c:1764:1: note: in expansion of macro 'accfg_group_set_field'
 1764 | accfg_group_set_field(group, val, desc_progress_limit)
      | ^~~~~~~~~~~~~~~~~~~~~
libaccfg.c:1736:52: note: format string is defined here
 1736 |                 rc = sprintf(group->group_buf, "%s/%s", \
      |                                                    ^~
libaccfg.c: In function 'accfg_group_set_batch_progress_limit':
libaccfg.c:1736:48: warning: '%s' directive argument is null [-Wformat-overflow=]
 1736 |                 rc = sprintf(group->group_buf, "%s/%s", \
      |                                                ^~~~~~~
libaccfg.c:1765:1: note: in expansion of macro 'accfg_group_set_field'
 1765 | accfg_group_set_field(group, val, batch_progress_limit)
      | ^~~~~~~~~~~~~~~~~~~~~
libaccfg.c:1736:52: note: format string is defined here
 1736 |                 rc = sprintf(group->group_buf, "%s/%s", \

The reason for this is that deprecated_attr() can potentially return NULL (which it probably doesn't but the compiler believes it's a possibility):

static const char *deprecated_attr(char *attr)
{
        int i;

        for (i = 0; i < (int) ARRAY_SIZE(attr_dict); i++)
                if (!strcmp(attr, attr_dict[i].key))
                        return attr_dict[i].val;

        return NULL;
}

I guess NULL could be replaced with a known invalid string instead, or "".

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