diff options
author | Vipin Sharma <vipinsh@google.com> | 2022-11-03 12:17:15 -0700 |
---|---|---|
committer | Sean Christopherson <seanjc@google.com> | 2022-11-16 10:03:24 -0800 |
commit | 018ea2d71a43372cb984021f03514dc6dd3d46df (patch) | |
tree | 0c8b29c542aa023906296179eb252c9eedbbb69c /tools/testing/selftests/kvm/include/test_util.h | |
parent | 0eb88a4121861ce3d5f925a183abb13ad954dbe6 (diff) | |
download | linux-018ea2d71a43372cb984021f03514dc6dd3d46df.tar.bz2 |
KVM: selftests: Add atoi_paranoid() to catch errors missed by atoi()
atoi() doesn't detect errors. There is no way to know that a 0 return
is correct conversion or due to an error.
Introduce atoi_paranoid() to detect errors and provide correct
conversion. Replace all atoi() calls with atoi_paranoid().
Signed-off-by: Vipin Sharma <vipinsh@google.com>
Suggested-by: David Matlack <dmatlack@google.com>
Suggested-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Sean Christopherson <seanjc@google.com>
Link: https://lore.kernel.org/r/20221103191719.1559407-4-vipinsh@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Diffstat (limited to 'tools/testing/selftests/kvm/include/test_util.h')
-rw-r--r-- | tools/testing/selftests/kvm/include/test_util.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h index befc754ce9b3..feae42863759 100644 --- a/tools/testing/selftests/kvm/include/test_util.h +++ b/tools/testing/selftests/kvm/include/test_util.h @@ -152,4 +152,6 @@ static inline void *align_ptr_up(void *x, size_t size) return (void *)align_up((unsigned long)x, size); } +int atoi_paranoid(const char *num_str); + #endif /* SELFTEST_KVM_TEST_UTIL_H */ |