From 5768032947ba741092e031cc22260ce86de4e4b2 Mon Sep 17 00:00:00 2001 From: Doug Rabson Date: Thu, 8 May 2008 11:01:46 +0000 Subject: [PATCH] Merge from the vendor branch and resolve conflicts. --- contrib/com_err/com_err.c | 9 ++++----- contrib/com_err/com_err.h | 15 +++++++------- contrib/com_err/com_right.h | 8 ++++---- contrib/com_err/compile_et.c | 19 +++++++++--------- contrib/com_err/compile_et.h | 5 +++-- contrib/com_err/lex.l | 6 ++++-- contrib/com_err/parse.y | 38 +++++++++++++++++++++--------------- 7 files changed, 54 insertions(+), 46 deletions(-) diff --git a/contrib/com_err/com_err.c b/contrib/com_err/com_err.c index f00c602646bb..b6ad85b94769 100644 --- a/contrib/com_err/com_err.c +++ b/contrib/com_err/com_err.c @@ -34,7 +34,7 @@ #ifdef HAVE_CONFIG_H #include -RCSID("$Id: com_err.c,v 1.18 2002/03/10 23:07:01 assar Exp $"); +RCSID("$Id: com_err.c 14930 2005-04-24 19:43:06Z lha $"); #endif #include #include @@ -51,15 +51,14 @@ error_message (long code) const char *p = com_right(_et_list, code); if (p == NULL) { if (code < 0) - sprintf(msg, "Unknown error %ld", code); + snprintf(msg, sizeof(msg), "Unknown error %ld", code); else p = strerror(code); } if (p != NULL && *p != '\0') { - strncpy(msg, p, sizeof(msg) - 1); - msg[sizeof(msg) - 1] = 0; + strlcpy(msg, p, sizeof(msg)); } else - sprintf(msg, "Unknown error %ld", code); + snprintf(msg, sizeof(msg), "Unknown error %ld", code); return msg; } diff --git a/contrib/com_err/com_err.h b/contrib/com_err/com_err.h index 6c1faa4bd5bd..22f1d5cdf6ba 100644 --- a/contrib/com_err/com_err.h +++ b/contrib/com_err/com_err.h @@ -32,7 +32,7 @@ */ /* $FreeBSD$ */ -/* $Id: com_err.h,v 1.9 2001/05/11 20:03:36 assar Exp $ */ +/* $Id: com_err.h 15566 2005-07-07 14:58:07Z lha $ */ /* MIT compatible com_err library */ @@ -43,11 +43,12 @@ #include #include +#include typedef void (*errf) __P((const char *, long, const char *, va_list)); -const char * error_message __P((long)); -int init_error_table __P((const char**, long, int)); +const char * error_message (long); +int init_error_table (const char**, long, int); void com_err_va __P((const char *, long, const char *, va_list)) __printflike(3, 0); @@ -55,11 +56,11 @@ void com_err_va __P((const char *, long, const char *, va_list)) void com_err __P((const char *, long, const char *, ...)) __printflike(3, 4); -errf set_com_err_hook __P((errf)); -errf reset_com_err_hook __P((void)); +errf set_com_err_hook (errf); +errf reset_com_err_hook (void); -const char *error_table_name __P((int num)); +const char *error_table_name (int num); -void add_to_error_table __P((struct et_list *new_table)); +void add_to_error_table (struct et_list *new_table); #endif /* __COM_ERR_H__ */ diff --git a/contrib/com_err/com_right.h b/contrib/com_err/com_right.h index 09e95fa0251c..74d386d8adab 100644 --- a/contrib/com_err/com_right.h +++ b/contrib/com_err/com_right.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. */ -/* $Id: com_right.h,v 1.11 2000/07/31 01:11:08 assar Exp $ */ +/* $Id: com_right.h 14551 2005-02-03 08:45:13Z lha $ */ /* $FreeBSD$ */ #ifndef __COM_RIGHT_H__ @@ -51,8 +51,8 @@ struct et_list { }; extern struct et_list *_et_list; -const char *com_right __P((struct et_list *list, long code)); -void initialize_error_table_r __P((struct et_list **, const char **, int, long)); -void free_error_table __P((struct et_list *)); +const char *com_right (struct et_list *list, long code); +void initialize_error_table_r (struct et_list **, const char **, int, long); +void free_error_table (struct et_list *); #endif /* __COM_RIGHT_H__ */ diff --git a/contrib/com_err/compile_et.c b/contrib/com_err/compile_et.c index 59d9de996d63..1c78325f4528 100644 --- a/contrib/com_err/compile_et.c +++ b/contrib/com_err/compile_et.c @@ -37,7 +37,7 @@ #include #if 0 -RCSID("$Id: compile_et.c,v 1.16 2002/08/20 12:44:51 joda Exp $"); +RCSID("$Id: compile_et.c 15426 2005-06-16 19:21:42Z lha $"); #endif #include @@ -48,7 +48,7 @@ extern FILE *yyin; extern void yyparse(void); -long base; +long base_id; int number; char *prefix; char *id_str; @@ -158,13 +158,13 @@ generate_h(void) fprintf(h_file, "typedef enum %s_error_number{\n", name); for(ec = codes; ec; ec = ec->next) { - fprintf(h_file, "\t%s = %ld%s\n", ec->name, base + ec->number, + fprintf(h_file, "\t%s = %ld%s\n", ec->name, base_id + ec->number, (ec->next != NULL) ? "," : ""); } fprintf(h_file, "} %s_error_number;\n", name); fprintf(h_file, "\n"); - fprintf(h_file, "#define ERROR_TABLE_BASE_%s %ld\n", name, base); + fprintf(h_file, "#define ERROR_TABLE_BASE_%s %ld\n", name, base_id); fprintf(h_file, "\n"); fprintf(h_file, "#endif /* %s */\n", fn); @@ -196,17 +196,17 @@ int main(int argc, char **argv) { char *p; - int optind = 0; + int optidx = 0; setprogname(argv[0]); - if(getarg(args, num_args, argc, argv, &optind)) + if(getarg(args, num_args, argc, argv, &optidx)) usage(1); if(help_flag) usage(0); - if(optind == argc) + if(optidx == argc) usage(1); - filename = argv[optind]; + filename = argv[optidx]; yyin = fopen(filename, "r"); if(yyin == NULL) err(1, "%s", filename); @@ -217,8 +217,7 @@ main(int argc, char **argv) p++; else p = filename; - strncpy(Basename, p, sizeof(Basename)); - Basename[sizeof(Basename) - 1] = '\0'; + strlcpy(Basename, p, sizeof(Basename)); Basename[strcspn(Basename, ".")] = '\0'; diff --git a/contrib/com_err/compile_et.h b/contrib/com_err/compile_et.h index 35e4863989ff..9b9db9c86daf 100644 --- a/contrib/com_err/compile_et.h +++ b/contrib/com_err/compile_et.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. */ -/* $Id: compile_et.h,v 1.6 2000/07/01 20:21:48 assar Exp $ */ +/* $Id: compile_et.h 15426 2005-06-16 19:21:42Z lha $ */ /* $FreeBSD$ */ #ifndef __COMPILE_ET_H__ @@ -41,13 +41,14 @@ #include #endif +#include #include #include #include #include #include -extern long base; +extern long base_id; extern int number; extern char *prefix; extern char name[128]; diff --git a/contrib/com_err/lex.l b/contrib/com_err/lex.l index b5f8db1e1e43..069fc9377d92 100644 --- a/contrib/com_err/lex.l +++ b/contrib/com_err/lex.l @@ -46,7 +46,7 @@ #include "lex.h" #if 0 -RCSID("$Id: lex.l,v 1.6 2000/06/22 00:42:52 assar Exp $"); +RCSID("$Id: lex.l 15143 2005-05-16 08:52:54Z lha $"); #endif static unsigned lineno = 1; @@ -92,7 +92,7 @@ getstring(void) int i = 0; int c; int quote = 0; - while((c = input()) != EOF){ + while(i < sizeof(x) - 1 && (c = input()) != EOF){ if(quote) { x[i++] = c; quote = 0; @@ -113,6 +113,8 @@ getstring(void) } x[i] = '\0'; yylval.string = strdup(x); + if (yylval.string == NULL) + err(1, "malloc"); return STRING; } diff --git a/contrib/com_err/parse.y b/contrib/com_err/parse.y index 960bcfa8f1e4..7e9cf1016ebf 100644 --- a/contrib/com_err/parse.y +++ b/contrib/com_err/parse.y @@ -36,7 +36,7 @@ #include "compile_et.h" #include "lex.h" #if 0 -RCSID("$Id: parse.y,v 1.11 2000/06/22 00:42:52 assar Exp $"); +RCSID("$Id: parse.y 15426 2005-06-16 19:21:42Z lha $"); #endif void yyerror (char *s); @@ -79,16 +79,14 @@ id : ID STRING et : ET STRING { - base = name2number($2); - strncpy(name, $2, sizeof(name)); - name[sizeof(name) - 1] = '\0'; + base_id = name2number($2); + strlcpy(name, $2, sizeof(name)); free($2); } | ET STRING STRING { - base = name2number($2); - strncpy(name, $3, sizeof(name)); - name[sizeof(name) - 1] = '\0'; + base_id = name2number($2); + strlcpy(name, $3, sizeof(name)); free($2); free($3); } @@ -104,24 +102,32 @@ statement : INDEX NUMBER } | PREFIX STRING { - prefix = realloc(prefix, strlen($2) + 2); - strcpy(prefix, $2); - strcat(prefix, "_"); + free(prefix); + asprintf (&prefix, "%s_", $2); + if (prefix == NULL) + errx(1, "malloc"); free($2); } | PREFIX { prefix = realloc(prefix, 1); + if (prefix == NULL) + errx(1, "malloc"); *prefix = '\0'; } | EC STRING ',' STRING { struct error_code *ec = malloc(sizeof(*ec)); + + if (ec == NULL) + errx(1, "malloc"); ec->next = NULL; ec->number = number; if(prefix && *prefix != '\0') { asprintf (&ec->name, "%s%s", prefix, $2); + if (ec->name == NULL) + errx(1, "malloc"); free($2); } else ec->name = $2; @@ -141,7 +147,7 @@ static long name2number(const char *str) { const char *p; - long base = 0; + long num = 0; const char *x = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz0123456789_"; if(strlen(str) > 4) { @@ -154,12 +160,12 @@ name2number(const char *str) yyerror("invalid character in table name"); return 0; } - base = (base << 6) + (q - x) + 1; + num = (num << 6) + (q - x) + 1; } - base <<= 8; - if(base > 0x7fffffff) - base = -(0xffffffff - base + 1); - return base; + num <<= 8; + if(num > 0x7fffffff) + num = -(0xffffffff - num + 1); + return num; } void