From a8a488a128a8124503d01da632c7290f6abc0752 Mon Sep 17 00:00:00 2001 From: David Levine Date: Sat, 22 Dec 2012 10:05:51 -0600 Subject: [PATCH] Changed type of name argument to m_getfld() from unsigned char * to unsigned char[NAMESZ]. --- h/prototypes.h | 2 +- sbr/m_getfld.c | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/h/prototypes.h b/h/prototypes.h index d62fb7a..c40e563 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -76,7 +76,7 @@ char *m_backup (char *); int m_convert (struct msgs *, char *); char *m_draft (char *, char *, int, int *); void m_eomsbr (int (*)(int)); -int m_getfld (int, unsigned char *, unsigned char *, int, FILE *); +int m_getfld (int, unsigned char[NAMESZ], unsigned char *, int, FILE *); int m_gmprot (void); char *m_maildir (char *); char *m_mailpath (char *); diff --git a/sbr/m_getfld.c b/sbr/m_getfld.c index fe88dc7..1d5d764 100644 --- a/sbr/m_getfld.c +++ b/sbr/m_getfld.c @@ -212,26 +212,21 @@ Subsequent calls provide the state returned by the previous call. Along the way, I thought of these possible interface changes that we might want to consider before rototilling the internals: -1) To improve interface documentation: - Change type of name argument from unsigned char * to unsigned char[NAMESZ]. - This would also be a step toward allowing the compiler to check for array - size consistency. - -2) To remove globals that don't need to be: +1) To remove globals that don't need to be: Change msg_style and msg_delim to be file static. -3) To remove a global: +2) To remove a global: Change bufsz to be in-out instead of in, and therefore int * instead of int, and use that instead of global msg_count. There are only 3 call sites that use msg_count so it wouldn't take much effort to remove use of it. Of course, all call sites would have to change to provide an int * instead of an int. Some now pass constants. -4) To remove the state argument from the signature: +3) To remove the state argument from the signature: Given the Current usage and Restriction above, the state variable could be removed from the signature and just retained internally. -5) To remove the Restriction above: +4) To remove the Restriction above: One approach would be for m_getfld() to retain multiple copies of that state, one per iob that it sees. Another approach would be for the caller to store it in an opaque struct, the address of which is passed @@ -304,7 +299,7 @@ extern int _filbuf(FILE*); int -m_getfld (int state, unsigned char *name, unsigned char *buf, +m_getfld (int state, unsigned char name[NAMESZ], unsigned char *buf, int bufsz, FILE *iob) { register unsigned char *bp, *cp, *ep, *sp; -- 1.7.10.4