From 630498caa440a62d226e4f69c26eb90bffbc7504 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Thu, 19 Jul 2018 07:53:13 +0200 Subject: [PATCH] ioconf: Update constant values Change constant values to avoid defining arrays size as type array[CONSTANT_VALUE + 1]; This is error-prone and not consistent with the rest of sysstat code. Signed-off-by: Sebastien GODARD --- ioconf.c | 34 +++++++++++++++++----------------- ioconf.h | 22 +++++++++++----------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/ioconf.c b/ioconf.c index 113fcd5..fa5fd99 100644 --- a/ioconf.c +++ b/ioconf.c @@ -141,11 +141,11 @@ int ioc_init(void) { FILE *fp; unsigned int i, major, indirect, count = 0; - char buf[IOC_LINESIZ + 1]; - char cfmt[IOC_FMTLEN + 1]; - char dfmt[IOC_FMTLEN + 1]; - char pfmt[IOC_FMTLEN + 1]; - char desc[IOC_DESCLEN + 1]; + char buf[IOC_LINESIZ]; + char cfmt[IOC_FMTLEN]; + char dfmt[IOC_FMTLEN]; + char pfmt[IOC_FMTLEN]; + char desc[IOC_DESCLEN]; struct ioc_entry *iocp = NULL; struct blk_config *blkp = NULL; char ioconf_name[64]; @@ -163,7 +163,7 @@ int ioc_init(void) /* Init ioc_refnr array */ memset(ioc_refnr, 0, sizeof(ioc_refnr)); - while (fgets(buf, IOC_LINESIZ, fp)) { + while (fgets(buf, IOC_LINESIZ - 1, fp)) { if ((*buf == '#') || (*buf == '\n')) continue; @@ -218,8 +218,8 @@ int ioc_init(void) iocp->desc = ioconf[indirect]->blkp->desc; } else { - IOC_ALLOC(iocp->desc, char, IOC_DESCLEN + 1); - strncpy(iocp->desc, desc, IOC_DESCLEN); + IOC_ALLOC(iocp->desc, char, IOC_DESCLEN); + strncpy(iocp->desc, desc, IOC_DESCLEN - 1); } ioc_refnr[indirect]++; ioconf[major] = iocp; @@ -287,8 +287,8 @@ int ioc_init(void) * exception info */ xblkp->ext_minor = iocp->ctrlno; - strncpy(xblkp->ext_name, blkp->name, IOC_NAMELEN + 1); - xblkp->ext_name[IOC_NAMELEN] = '\0'; + strncpy(xblkp->ext_name, blkp->name, IOC_NAMELEN); + xblkp->ext_name[IOC_NAMELEN - 1] = '\0'; xblkp->ext = 1; continue; } @@ -300,8 +300,8 @@ int ioc_init(void) /* basename of device + provided string + controller # */ if (*cfmt == '*') { - strncpy(blkp->cfmt, blkp->name, IOC_FMTLEN); - blkp->cfmt[IOC_FMTLEN] = '\0'; + strncpy(blkp->cfmt, blkp->name, IOC_FMTLEN - 1); + blkp->cfmt[IOC_FMTLEN - 1] = '\0'; } else { sprintf(blkp->cfmt, "%s%s%%d", blkp->name, cfmt); @@ -317,7 +317,7 @@ int ioc_init(void) break; case '%': - strncpy(blkp->dfmt, dfmt + 1, IOC_FMTLEN); + strncpy(blkp->dfmt, dfmt + 1, IOC_FMTLEN - 1); /* fallthrough to next case */ case 'd': blkp->cconv = ioc_ito10; @@ -337,7 +337,7 @@ int ioc_init(void) iocp->desc = NULL; iocp->basemajor = major; ioconf[major] = iocp; - strncpy(blkp->desc, desc, IOC_DESCLEN); + strncpy(blkp->desc, desc, IOC_DESCLEN - 1); blkp = NULL; iocp = NULL; ++count; } @@ -386,7 +386,7 @@ free_and_return: char *ioc_name(unsigned int major, unsigned int minor) { - static char name[IOC_DEVLEN + 1]; + static char name[IOC_DEVLEN]; struct ioc_entry *p; int base, offset; @@ -411,8 +411,8 @@ char *ioc_name(unsigned int major, unsigned int minor) /* Is this an extension record? */ if (p->blkp->ext && (p->blkp->ext_minor == minor)) { - strncpy(name, p->blkp->ext_name, IOC_DEVLEN + 1); - name[IOC_DEVLEN] = '\0'; + strncpy(name, p->blkp->ext_name, IOC_DEVLEN); + name[IOC_DEVLEN - 1] = '\0'; return (name); } diff --git a/ioconf.h b/ioconf.h index 93a755e..88c5466 100644 --- a/ioconf.h +++ b/ioconf.h @@ -10,11 +10,11 @@ #include "sysconfig.h" -#define IOC_NAMELEN 31 -#define IOC_DESCLEN 63 -#define IOC_DEVLEN 47 -#define IOC_LINESIZ 255 -#define IOC_FMTLEN 15 +#define IOC_NAMELEN 32 +#define IOC_DESCLEN 64 +#define IOC_DEVLEN 48 +#define IOC_LINESIZ 256 +#define IOC_FMTLEN 16 #ifndef MINORBITS #define MINORBITS 20 @@ -49,20 +49,20 @@ struct blk_config { - char name[IOC_NAMELEN + 1]; /* device basename */ - char cfmt[IOC_FMTLEN + 1]; /* controller format string */ - char dfmt[IOC_FMTLEN + 1]; /* disk format string */ - char pfmt[IOC_FMTLEN + 1]; /* partition format string */ + char name[IOC_NAMELEN]; /* device basename */ + char cfmt[IOC_FMTLEN]; /* controller format string */ + char dfmt[IOC_FMTLEN]; /* disk format string */ + char pfmt[IOC_FMTLEN]; /* partition format string */ /* ctrlno is in the ioc_entry */ unsigned int ctrl_explicit; /* use "cN" in name */ unsigned int dcount; /* number of devices handled by this major */ unsigned int pcount; /* partitions per device */ - char desc[IOC_DESCLEN + 1]; + char desc[IOC_DESCLEN]; /* disk info unit # conversion function */ char *(*cconv)(unsigned int); /* extension properties (all this for initrd?) */ - char ext_name[IOC_NAMELEN + 1]; + char ext_name[IOC_NAMELEN]; unsigned int ext; /* flag - this is an extension record */ unsigned int ext_minor; /* which minor does this apply to */ }; -- 2.40.0