Some minor fixes
Phil Sutter
reviewercover Some minor fixes
These are some patches I found while cleaning up the attic. They add a gitignore file, fix for a compiler warning and simplify code in libarptc a bit.
Phil Sutter (3):
Add .gitignore
Eliminate compiler warning about size passed to strncmp()
libarptc: Simplify alloc_handle by using calloc()
.gitignore | 4 ++++ arptables.c | 3 +-- libarptc/libarptc_incl.c | 11 +++-------- 3 files changed, 8 insertions(+), 10 deletions(-) create mode 100644 .gitignore
Signature · 1 line
2.24.0
Phil Sutter
reviewerPATCH 1/3 Add .gitignore
Ignore temporary files, created arptables-legacy binary and any present tags file.
--- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .gitignore
.gitignore new file +4 -0
@@ -0,0 +1,4 @@ +*.a +*.o +/arptables-legacy +/tags
Signature · 1 line
2.24.0
Re: [arptables PATCH 1/3] Add .gitignore
Quoted 4 lines · Phil Sutter
Ignore temporary files, created arptables-legacy binary and any present tags file.
Signed-off-by Phil Sutter <[email protected]>
Phil Sutter
reviewerPATCH 2/3 Eliminate compiler warning about size passed to strncmp()
In reply to Phil SutterGcc complains about the size being equal to destination size, despite the nul character being explicitly set in following line.
Reduce size by one to make gcc happy. While being at it, drop the explicit nul character assignment - it is not needed as the buffer was allocated by calloc().
--- arptables.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arptables.c +1 -2
@@ -2065,8 +2065,7 @@ int do_command(int argc, char *argv[], char **table, arptc_handle_t *handle) target->t =fw_calloc (1 , size); target->t->u.target_size = size; -strncpy (target->t->u.user.name, jumpto,sizeof (target->t->u.user.name)); - target->t->u.user.name[sizeof (target->t->u.user.name)-1 ] ='\0' ; +strncpy (target->t->u.user.name, jumpto,sizeof (target->t->u.user.name) -1 ); target->t->u.user.revision = target->revision;/* target->init(target->t, &fw.nfcache);
Signature · 1 line
2.24.0
Re: [arptables PATCH 2/3] Eliminate compiler warning about size passed to strncmp()
Quoted 9 lines · Phil Sutter
Gcc complains about the size being equal to destination size, despite the nul character being explicitly set in following line.
Reduce size by one to make gcc happy. While being at it, drop the explicit nul character assignment - it is not needed as the buffer was allocated by
calloc().Fixes 8f586939999e0 ("fix potential buffer overflows reported by static analysis")Signed-off-by Phil Sutter <[email protected]>
Phil Sutter
reviewerPATCH 3/3 libarptc: Simplify alloc_handle by using calloc()
In reply to Phil SutterNo need to explicitly set fields to zero when using calloc().
--- libarptc/libarptc_incl.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
libarptc/libarptc_incl.c +3 -8
@@ -191,21 +191,16 @@ alloc_handle(const char *tablename, unsigned int size, unsigned int num_rules) + size + num_rules *sizeof (struct counter_map ); -if ((h =malloc (len)) ==NULL ) { +if ((h =calloc (1 , len)) ==NULL ) { errno =ENOMEM ;return NULL ; } - h->changed =0 ; - h->cache_num_chains =0 ; - h->cache_chain_heads =NULL ; h->counter_map = (void *)h +sizeof (STRUCT_TC_HANDLE ) + size; -strncpy (h->info.name, tablename,sizeof (h->info.name)); - h->info.name[sizeof (h->info.name)-1 ] ='\0' ; -strncpy (h->entries.name, tablename,sizeof (h->entries.name)); - h->entries.name[sizeof (h->entries.name)-1 ] ='\0' ; +strncpy (h->info.name, tablename,sizeof (h->info.name) -1 ); +strncpy (h->entries.name, tablename,sizeof (h->entries.name) -1 );return h; }
Signature · 1 line
2.24.0
Re: [arptables PATCH 3/3] libarptc: Simplify alloc_handle by using calloc()
Quoted 1 line · Phil Sutter
No need to explicitly set fields to zero when using
calloc().