[Beignet] [PATCH V2] Fix the bug of crash when we pass -I path with spaces.
He Junyan
junyan.he at inbox.com
Wed Jan 20 01:59:14 PST 2016
V2 just fix some typo, please just ignore the previous one.
This patch should be merget to master and release1.1
On Wed, Jan 20, 2016 at 05:57:20PM +0800, junyan.he at inbox.com wrote:
> Date: Wed, 20 Jan 2016 17:57:20 +0800
> From: junyan.he at inbox.com
> To: beignet at lists.freedesktop.org
> Subject: [Beignet] [PATCH V2] Fix the bug of crash when we pass -I path
> with spaces.
> X-Mailer: git-send-email 1.7.9.5
>
> From: Junyan He <junyan.he at linux.intel.com>
>
> We failed to handle -I "/XX X/YY YY/" like path passed
> from the build option. We need to consider the spaces
> here and pass it correctly to Clang.
>
> Signed-off-by: Junyan He <junyan.he at linux.intel.com>
> ---
> backend/src/backend/program.cpp | 51 +++++++++++++++++++++++++++++++++++++----
> 1 file changed, 47 insertions(+), 4 deletions(-)
>
> diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
> index f886d03..c8bc688 100644
> --- a/backend/src/backend/program.cpp
> +++ b/backend/src/backend/program.cpp
> @@ -770,17 +770,60 @@ namespace gbe {
> bool useDefaultCLCVersion = true;
>
> if (options) {
> - char *str = (char *)malloc(sizeof(char) * (strlen(options) + 1));
> - memcpy(str, options, strlen(options) + 1);
> - std::string optionStr(str);
> + char *c_str = (char *)malloc(sizeof(char) * (strlen(options) + 1));
> + memcpy(c_str, options, strlen(options) + 1);
> + std::string optionStr(c_str);
> const std::string unsupportedOptions("-cl-denorms-are-zero, -cl-strict-aliasing, -cl-opt-disable,"
> "-cl-no-signed-zeros, -cl-fp32-correctly-rounded-divide-sqrt");
>
> const std::string uncompatiblePCHOptions = ("-cl-single-precision-constant, -cl-fast-relaxed-math, -cl-std=CL1.1, -cl-finite-math-only");
> const std::string fastMathOption = ("-cl-fast-relaxed-math");
> while (end != std::string::npos) {
> + /* need to handle -I"/XX X/X XX" with spaces first. */
> + if (optionStr[start] == '-' && optionStr[start + 1] == 'I') {
> + end = start + 2;
> + while(end < optionStr.size() && optionStr[end] == ' ') // Ignore the spaces
> + end++;
> +
> + if (end == optionStr.size()) { //reach the end and no content, ignore
> + free(c_str);
> + return true;
> + }
> +
> + if (optionStr[end] != '"') { // just a normal path without " "
> + clOpt.push_back("-I");
> + start = end;
> + continue;
> + }
> +
> + end++;
> + start = end;
> + clOpt.push_back("-I");
> +
> + /* find the second " */
> + while (end < optionStr.size() && optionStr[end] != '"')
> + end++;
> +
> + if (optionStr[end] != '"') {
> + free(c_str);
> + return false;
> + }
> +
> + if (end == start + 1) { // the case of "", ignore
> + start = end + 1;
> + continue;
> + }
> +
> + std::string IPath = optionStr.substr(start, end - start);
> + clOpt.push_back(IPath.c_str());
> + start = end + 1;
> + continue;
> + }
> +
> +
> end = optionStr.find(' ', start);
> std::string str = optionStr.substr(start, end - start);
> +
> start = end + 1;
> if(str.size() == 0)
> continue;
> @@ -822,7 +865,7 @@ namespace gbe {
>
> clOpt.push_back(str);
> }
> - free(str);
> + free(c_str);
> }
>
> if (useDefaultCLCVersion) {
> --
> 1.9.1
>
>
>
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet
More information about the Beignet
mailing list