[clinfo] 14/55: Realloc bufsz only if no error
Andreas Beckmann
anbe at moszumanska.debian.org
Sat Jan 13 14:39:59 UTC 2018
This is an automated email from the git hooks/post-receive script.
anbe pushed a commit to branch master
in repository clinfo.
commit 554b93d96dfdfb19bf65a40ad2c20fa80c8dbaf9
Author: Giuseppe Bilotta <giuseppe.bilotta at gmail.com>
Date: Thu Feb 9 14:06:59 2017 +0100
Realloc bufsz only if no error
If the size query call didn't return CL_SUCCESS, there is no need to
resize the buffer, since we're not going to use its value anyway. Plus,
the new size might actually be completely bogus and cause issues.
This should fix Debian Bug #848169.
---
src/clinfo.c | 24 ++++++++++++------------
src/strbuf.h | 2 +-
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/src/clinfo.c b/src/clinfo.c
index 529d665..2909a0b 100644
--- a/src/clinfo.c
+++ b/src/clinfo.c
@@ -316,12 +316,12 @@ int
platform_info_str(cl_platform_id pid, cl_platform_info param, const char* pname, const struct platform_info_checks * chk UNUSED)
{
error = clGetPlatformInfo(pid, param, 0, NULL, &nusz);
- if (nusz > bufsz) {
- REALLOC(strbuf, nusz, current_param);
- bufsz = nusz;
- }
had_error = REPORT_ERROR2("get %s size");
if (!had_error) {
+ if (nusz > bufsz) {
+ REALLOC(strbuf, nusz, current_param);
+ bufsz = nusz;
+ }
error = clGetPlatformInfo(pid, param, bufsz, strbuf, NULL);
had_error = REPORT_ERROR2("get %s");
}
@@ -780,12 +780,12 @@ int device_info_str_get(cl_device_id dev, cl_device_info param, const char *pnam
{
current_param = pname;
error = clGetDeviceInfo(dev, param, 0, NULL, &nusz);
- if (nusz > bufsz) {
- REALLOC(strbuf, nusz, current_param);
- bufsz = nusz;
- }
had_error = REPORT_ERROR2("get %s size");
if (!had_error) {
+ if (nusz > bufsz) {
+ REALLOC(strbuf, nusz, current_param);
+ bufsz = nusz;
+ }
error = clGetDeviceInfo(dev, param, bufsz, strbuf, NULL);
had_error = REPORT_ERROR2("get %s");
}
@@ -2531,12 +2531,12 @@ int
icdl_info_str(cl_icdl_info param, const char* pname)
{
error = clGetICDLoaderInfoOCLICD(param, 0, NULL, &nusz);
- if (nusz > bufsz) {
- REALLOC(strbuf, nusz, current_param);
- bufsz = nusz;
- }
had_error = REPORT_ERROR2("get %s size");
if (!had_error) {
+ if (nusz > bufsz) {
+ REALLOC(strbuf, nusz, current_param);
+ bufsz = nusz;
+ }
error = clGetICDLoaderInfoOCLICD(param, bufsz, strbuf, NULL);
had_error = REPORT_ERROR2("get %s");
}
diff --git a/src/strbuf.h b/src/strbuf.h
index 8fc112f..c936932 100644
--- a/src/strbuf.h
+++ b/src/strbuf.h
@@ -12,11 +12,11 @@ size_t bufsz, nusz;
#define GET_STRING(cmd, param, param_str, ...) do { \
error = cmd(__VA_ARGS__, param, 0, NULL, &nusz); \
+ if (REPORT_ERROR("get " param_str " size")) break; \
if (nusz > bufsz) { \
REALLOC(strbuf, nusz, #param); \
bufsz = nusz; \
} \
- if (REPORT_ERROR("get " param_str " size")) break; \
error = cmd(__VA_ARGS__, param, bufsz, strbuf, NULL); \
REPORT_ERROR("get " param_str); \
} while (0)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opencl/clinfo.git
More information about the Pkg-opencl-commits
mailing list