[LTP] [PATCH 2/2] Handle high record counts and prevent integer overflow
Vishal Chourasia
vishalc@linux.ibm.com
Mon Aug 14 08:18:10 CEST 2023
- The type of `records_read` is now `unsigned long long`, expanding the maximum
record count.
- Implemented error check for integer overflow during the addition of
`local_records_read` to `records_read`.
- Added error message and program exit upon detection of integer overflow.
Reviewed-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Reviewed-by: Shrikanth Hegde <sshegde@linux.vnet.ibm.com>
Signed-off-by: Vishal Chourasia <vishalc@linux.ibm.com>
---
utils/benchmark/ebizzy-0.3/ebizzy.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/utils/benchmark/ebizzy-0.3/ebizzy.c b/utils/benchmark/ebizzy-0.3/ebizzy.c
index 1af004d9d..b89a0a97a 100644
--- a/utils/benchmark/ebizzy-0.3/ebizzy.c
+++ b/utils/benchmark/ebizzy-0.3/ebizzy.c
@@ -83,7 +83,7 @@ static char **hole_mem;
static unsigned int page_size;
static time_t start_time;
static volatile int threads_go;
-static unsigned int records_read;
+static unsigned long long records_read;
pthread_mutex_t records_read_lock;
@@ -368,13 +368,13 @@ static inline unsigned int rand_num(unsigned int max, unsigned int *state)
*
*/
-static unsigned int search_mem(void)
+static unsigned long long search_mem(void)
{
record_t key, *found;
record_t *src, *copy;
unsigned int chunk;
size_t copy_size = chunk_size;
- unsigned int i;
+ unsigned long long i;
unsigned int state = 0;
for (i = 0; threads_go == 1; i++) {
@@ -425,17 +425,29 @@ static unsigned int search_mem(void)
static void *thread_run(void *arg __attribute__((unused)))
{
+ unsigned long long old_records_read, local_records_read;
+
if (verbose > 1)
printf("Thread started\n");
/* Wait for the start signal */
-
while (threads_go == 0) ;
+
+ local_records_read = search_mem();
pthread_mutex_lock(&records_read_lock);
- records_read += search_mem();
+ old_records_read = records_read;
+ records_read += local_records_read;
pthread_mutex_unlock(&records_read_lock);
+ if (old_records_read > records_read || local_records_read > records_read) {
+ fprintf(stderr, "Error: Integer overflow occurred!\n");
+ fprintf(stderr, "Current records_read: %llu\n", records_read);
+ fprintf(stderr, "Local records_read: %llu\n", local_records_read);
+ fprintf(stderr, "Old records_read: %llu\n", old_records_read);
+ exit(1);
+ }
+
if (verbose > 1)
printf("Thread finished, %f seconds\n",
difftime(time(NULL), start_time));
--
2.39.3
More information about the ltp
mailing list