summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKeith Bostic <keith.bostic@mongodb.com>2016-05-25 12:25:13 -0400
committersueloverso <sue@mongodb.com>2016-05-25 12:25:13 -0400
commit5c70c8168784381d4d3afaeebcd81fd8b2909a9a (patch)
tree7224e9af1eb4626e00bf245977f4b5d134d38d97 /test
parentc0a04f1d22075b63f8da063226e6871a9ccfd78e (diff)
downloadmongo-5c70c8168784381d4d3afaeebcd81fd8b2909a9a.tar.gz
Wt 2661 coverity (#2746)
* WT-2661: Coverity failures: 1356050-1356053 CID 1356050: (NULL_RETURNS) Dereferencing a pointer that might be null "opts->home" when calling "snprintf". CID 1356050: (NULL_RETURNS) Dereferencing a pointer that might be null "opts->uri" when calling "snprintf". * Assigning address of auto variable '_opts' to static (it's an auto variable in main(), so it's safe, but make lint happy). * Coverity appears to be confused by argv handling and eventually passing NULL to snprintf. 2. var_assign_alias: Assigning: opts->progname = argv[0]. Both are now tainted. 47. vararg_transitive: Call to snprintf with tainted argument opts->progname taints NULL. 48. tainted_data_sink_lv_call: Passing tainted variable 0UL to tainted data sink snprintf. NULL is tainted? I'm hoping that using a strlen() call to figure out the string length instead of snprintf() will make this one go away. * test_wt2246_col_append wasn't actually doing any work, set nrecords to a 20 million default. * KNF * Don't use "inline" in example programs, it requires Windows #ifdef's.
Diffstat (limited to 'test')
-rw-r--r--test/csuite/wt1965_col_efficiency/main.c4
-rw-r--r--test/csuite/wt2246_col_append/main.c7
-rw-r--r--test/utility/parse_opts.c13
-rw-r--r--test/utility/test_util.h2
4 files changed, 13 insertions, 13 deletions
diff --git a/test/csuite/wt1965_col_efficiency/main.c b/test/csuite/wt1965_col_efficiency/main.c
index f1a561a3212..2882ce9cdf5 100644
--- a/test/csuite/wt1965_col_efficiency/main.c
+++ b/test/csuite/wt1965_col_efficiency/main.c
@@ -48,8 +48,8 @@ static uint64_t g_ts = 0;
* Each thread inserts a set of keys into the record store database. The keys
* are generated in such a way that there are large gaps in the key range.
*/
-static void
-*thread_func(void *arg)
+static void *
+thread_func(void *arg)
{
TEST_OPTS *opts;
WT_CURSOR *cursor, *idx_cursor;
diff --git a/test/csuite/wt2246_col_append/main.c b/test/csuite/wt2246_col_append/main.c
index 12e040114b3..3ac96677ed0 100644
--- a/test/csuite/wt2246_col_append/main.c
+++ b/test/csuite/wt2246_col_append/main.c
@@ -45,7 +45,7 @@
void (*custom_die)(void) = NULL;
/* Needs to be global for signal handling. */
-TEST_OPTS *opts;
+TEST_OPTS *opts, _opts;
static void
page_init(uint64_t n)
@@ -92,11 +92,11 @@ onsig(int signo)
}
#define N_APPEND_THREADS 6
+#define N_RECORDS (20 * WT_MILLION)
int
main(int argc, char *argv[])
{
- TEST_OPTS _opts;
WT_SESSION *session;
clock_t ce, cs;
pthread_t idlist[100];
@@ -107,6 +107,7 @@ main(int argc, char *argv[])
memset(opts, 0, sizeof(*opts));
opts->table_type = TABLE_ROW;
opts->n_append_threads = N_APPEND_THREADS;
+ opts->nrecords = N_RECORDS;
testutil_check(testutil_parse_opts(argc, argv, opts));
testutil_make_work_dir(opts->home);
@@ -146,7 +147,7 @@ main(int argc, char *argv[])
testutil_check(pthread_join(idlist[i], NULL));
ce = clock();
- printf("%" PRIu64 "M: %.2lf\n",
+ printf("%" PRIu64 "M records: %.2lf processor seconds\n",
opts->max_inserted_id / MILLION,
(ce - cs) / (double)CLOCKS_PER_SEC);
diff --git a/test/utility/parse_opts.c b/test/utility/parse_opts.c
index 66646893ae6..4054f318259 100644
--- a/test/utility/parse_opts.c
+++ b/test/utility/parse_opts.c
@@ -38,7 +38,7 @@ extern char *__wt_optarg; /* argument associated with option */
* Parse command line options for a test case.
*/
int
-testutil_parse_opts(int argc, char *argv[], TEST_OPTS *opts)
+testutil_parse_opts(int argc, char * const *argv, TEST_OPTS *opts)
{
int ch;
size_t len;
@@ -52,8 +52,7 @@ testutil_parse_opts(int argc, char *argv[], TEST_OPTS *opts)
else
++opts->progname;
- while ((ch =
- __wt_getopt(opts->progname,
+ while ((ch = __wt_getopt(opts->progname,
argc, argv, "A:h:n:o:pR:T:t:vW:")) != EOF)
switch (ch) {
case 'A': /* Number of append threads */
@@ -120,13 +119,13 @@ testutil_parse_opts(int argc, char *argv[], TEST_OPTS *opts)
* Setup the home directory. It needs to be unique for every test
* or the auto make parallel tester gets upset.
*/
- len = (size_t)snprintf(NULL, 0, "WT_TEST.%s", opts->progname) + 1;
- opts->home = (char *)malloc(len);
+ len = strlen("WT_TEST.") + strlen(opts->progname) + 10;
+ opts->home = dmalloc(len);
snprintf(opts->home, len, "WT_TEST.%s", opts->progname);
/* Setup the default URI string */
- len = (size_t)snprintf(NULL, 0, "table:%s", opts->progname) + 1;
- opts->uri = (char *)malloc(len);
+ len = strlen("table:") + strlen(opts->progname) + 10;
+ opts->uri = dmalloc(len);
snprintf(opts->uri, len, "table:%s", opts->progname);
return (0);
diff --git a/test/utility/test_util.h b/test/utility/test_util.h
index 073feba4ec2..6417c5a326b 100644
--- a/test/utility/test_util.h
+++ b/test/utility/test_util.h
@@ -121,7 +121,7 @@ void *dstrdup(const void *);
void testutil_clean_work_dir(char *);
void testutil_cleanup(TEST_OPTS *);
void testutil_make_work_dir(char *);
-int testutil_parse_opts(int, char *[], TEST_OPTS *);
+int testutil_parse_opts(int, char * const *, TEST_OPTS *);
void testutil_work_dir_from_path(char *, size_t, const char *);
void *thread_append(void *);
void *thread_insert_append(void *);