Skip to content

Commit

Permalink
ioconf: Update constant values
Browse files Browse the repository at this point in the history
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 <sysstat@users.noreply.github.com>
  • Loading branch information
sysstat committed Jul 19, 2018
1 parent 9a336f6 commit 630498c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
34 changes: 17 additions & 17 deletions ioconf.c
Expand Up @@ -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];
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -386,7 +386,7 @@ int ioc_init(void)

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;

Expand All @@ -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);
}

Expand Down
22 changes: 11 additions & 11 deletions ioconf.h
Expand Up @@ -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
Expand Down Expand Up @@ -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 */
};
Expand Down

0 comments on commit 630498c

Please sign in to comment.