(plurize): Fix the strncat() len parameter to prevent an overflow of buf.
(numstr, esplur, splur, iesplur, plurize): Move the prototype defintions from misc.h to prototypes.h. Remove unneccessary headers in plur.c.
This commit is contained in:
parent
fdcbb5912d
commit
d581485d32
3 changed files with 15 additions and 13 deletions
|
@ -135,11 +135,6 @@ extern int daemonize;
|
||||||
double dmax(double n1, double n2);
|
double dmax(double n1, double n2);
|
||||||
double dmin(double n1, double n2);
|
double dmin(double n1, double n2);
|
||||||
|
|
||||||
extern s_char *numstr(s_char buf[], int n);
|
|
||||||
extern s_char *esplur(int n);
|
|
||||||
extern s_char *splur(int n);
|
|
||||||
extern s_char *iesplur(int n);
|
|
||||||
extern char *plurize(char *buf, int max_len, int n);
|
|
||||||
extern char *getstarg(char *input, char *prompt, char buf[]);
|
extern char *getstarg(char *input, char *prompt, char buf[]);
|
||||||
extern char *getstring(char *prompt, char buf[]);
|
extern char *getstring(char *prompt, char buf[]);
|
||||||
extern char *ugetstring(char *prompt, char buf[]);
|
extern char *ugetstring(char *prompt, char buf[]);
|
||||||
|
|
|
@ -391,6 +391,12 @@ extern int parse(char *, char **, char **, char *, char **);
|
||||||
extern int ldround(double, int);
|
extern int ldround(double, int);
|
||||||
extern int roundintby(int, int);
|
extern int roundintby(int, int);
|
||||||
extern int scthash(register int, register int, int);
|
extern int scthash(register int, register int, int);
|
||||||
|
/* plur.c */
|
||||||
|
extern s_char *numstr(s_char buf[], int n);
|
||||||
|
extern s_char *esplur(int n);
|
||||||
|
extern s_char *splur(int n);
|
||||||
|
extern s_char *iesplur(int n);
|
||||||
|
extern char *plurize(char *buf, int max_len, int n);
|
||||||
/* more in misc.h */
|
/* more in misc.h */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -31,8 +31,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "misc.h"
|
#include "prototypes.h"
|
||||||
#include "gen.h"
|
|
||||||
|
|
||||||
s_char *
|
s_char *
|
||||||
splur(int n)
|
splur(int n)
|
||||||
|
@ -61,19 +60,21 @@ iesplur(int n)
|
||||||
char *
|
char *
|
||||||
plurize(char *buf, int max_len, int n)
|
plurize(char *buf, int max_len, int n)
|
||||||
{
|
{
|
||||||
if (!strlen(buf) || n <= 1)
|
size_t size = strlen(buf);
|
||||||
|
|
||||||
|
if (size || n <= 1)
|
||||||
return buf;
|
return buf;
|
||||||
|
|
||||||
switch(buf[strlen(buf) - 1]) {
|
switch(buf[size - 1]) {
|
||||||
case 'y':
|
case 'y':
|
||||||
buf[strlen(buf) -1] = '\0';
|
buf[size - 1] = '\0';
|
||||||
strncat(buf, "ies", max_len - 1);
|
strncat(buf, "ies", max_len - size - 1);
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
strncat(buf, "es", max_len - 1);
|
strncat(buf, "es", max_len - size - 1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
strncat(buf, "s", max_len - 1);
|
strncat(buf, "s", max_len - size - 1);
|
||||||
}
|
}
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue