From: David Matlack <dmatlack@google.com>
To: kvm@vger.kernel.org
Cc: jmattson@google.com, David Matlack <dmatlack@google.com>
Subject: [kvm-unit-tests PATCH 2/3] api: fix "ignoring return value" of posix_memalign errors
Date: Wed, 24 May 2017 14:31:22 -0700 [thread overview]
Message-ID: <20170524213123.71538-2-dmatlack@google.com> (raw)
In-Reply-To: <20170524213123.71538-1-dmatlack@google.com>
posix_memalign returns zero on success and an errno value otherwise. The
value of the global variable "errno" is actually indeterminiate after a
call to posix_memalign(), according to the man page.
This patch also fixes the compilation errors:
api/dirty-log.cc:55:50: error: ignoring return value of ‘int posix_memalign(void**, size_t, size_t)’, declared with attribute warn_unused_result [-Werror=unused-result]
posix_memalign(&logged_slot_virt, 4096, 4096);
api/identity.cc:23:41: error: ignoring return value of ‘int posix_memalign(void**, size_t, size_t)’, declared with attribute warn_unused_result [-Werror=unused-result]
posix_memalign(&tss, 4096, 4 * 4096);
Signed-off-by: David Matlack <dmatlack@google.com>
---
api/dirty-log.cc | 5 ++++-
api/identity.cc | 6 +++---
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/api/dirty-log.cc b/api/dirty-log.cc
index 47fbac2b1cc6..9891e98fde9e 100644
--- a/api/dirty-log.cc
+++ b/api/dirty-log.cc
@@ -52,7 +52,10 @@ int test_main(int ac, char **av)
kvm::vm vm(sys);
mem_map memmap(vm);
void* logged_slot_virt;
- posix_memalign(&logged_slot_virt, 4096, 4096);
+ int ret = posix_memalign(&logged_slot_virt, 4096, 4096);
+ if (ret) {
+ throw errno_exception(ret);
+ }
volatile int* shared_var = static_cast<volatile int*>(logged_slot_virt);
identity::hole hole(logged_slot_virt, 4096);
identity::vm ident_vm(vm, memmap, hole);
diff --git a/api/identity.cc b/api/identity.cc
index 6dd42315a0af..24609ef9d6d0 100644
--- a/api/identity.cc
+++ b/api/identity.cc
@@ -20,9 +20,9 @@ hole::hole(void* address, size_t size)
vm::vm(kvm::vm& vm, mem_map& mmap, hole h)
{
- posix_memalign(&tss, 4096, 4 * 4096);
- if (!tss) {
- throw errno_exception(errno);
+ int ret = posix_memalign(&tss, 4096, 4 * 4096);
+ if (ret) {
+ throw errno_exception(ret);
}
uint64_t hole_gpa = reinterpret_cast<uintptr_t>(h.address);
--
2.13.0.219.gdb65acc882-goog
next prev parent reply other threads:[~2017-05-24 21:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-24 21:31 [kvm-unit-tests PATCH 1/3] x86: fix "format not a string literal" errors David Matlack
2017-05-24 21:31 ` David Matlack [this message]
2017-05-24 21:31 ` [kvm-unit-tests PATCH 3/3] api: add api binaries to .gitignore David Matlack
2017-06-07 14:24 ` [kvm-unit-tests PATCH 1/3] x86: fix "format not a string literal" errors Radim Krčmář
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170524213123.71538-2-dmatlack@google.com \
--to=dmatlack@google.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox