From acd73a13652886550afb341d77eab02c28387bf2 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Fri, 28 Oct 2011 20:38:08 -0500 Subject: [PATCH] top: provided for nls table integrity validation --- top/top.h | 1 + top/top_nls.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/top/top.h b/top/top.h index 866fc5e4..fdb6449e 100644 --- a/top/top.h +++ b/top/top.h @@ -41,6 +41,7 @@ //#define TREE_NORESET /* sort keys do NOT force forest view OFF */ //#define TREE_ONEPASS /* for speed, tolerate dangling children */ //#define USE_X_COLHDR /* emphasize header vs. whole col, for 'x' */ +//#define VALIDATE_NLS /* validate integrity of all 3 nls tables */ /*###### Notes, etc. ###################################################*/ diff --git a/top/top_nls.c b/top/top_nls.c index b9a772c7..034e7545 100644 --- a/top/top_nls.c +++ b/top/top_nls.c @@ -589,7 +589,34 @@ static void build_uniq_nsltab (void) { /* * Duh... */ void initialize_nsl (void) { +#ifdef VALIDATE_NLS + static const char *nls_err ="\t%s_nlstab[%d] == NULL\n"; + int i; + + memset(Desc_nlstab, 0, sizeof(Desc_nlstab)); + build_desc_nlstab(); + for (i = 0; i < P_MAXPFLGS; i++) + if (!Desc_nlstab[i]) { + fprintf(stderr, nls_err, "Desc", i); + exit(1); + } + memset(Norm_nlstab, 0, sizeof(Norm_nlstab)); + build_norm_nlstab(); + for (i = 0; i < norm_MAX; i++) + if (!Norm_nlstab[i]) { + fprintf(stderr, nls_err, "Norm", i); + exit(1); + } + memset(Uniq_nlstab, 0, sizeof(Uniq_nlstab)); + build_uniq_nsltab(); + for (i = 0; i < uniq_MAX; i++) + if (!Uniq_nlstab[i]) { + fprintf(stderr, nls_err, "Uniq", i); + exit(1); + } +#else build_desc_nlstab(); build_norm_nlstab(); build_uniq_nsltab(); +#endif }