Skip to content

Instantly share code, notes, and snippets.

@jumapico
Created March 18, 2015 17:49
Show Gist options
  • Save jumapico/64e1fb1e0493960701bc to your computer and use it in GitHub Desktop.
Save jumapico/64e1fb1e0493960701bc to your computer and use it in GitHub Desktop.
From e36f3d404849480c788ac9a3f6d0941b679aed5a Mon Sep 17 00:00:00 2001
From: Juan Picca <[email protected]>
Date: Wed, 18 Mar 2015 14:37:09 -0300
Subject: [PATCH] Fix json escape string
Fixes escape quotes in json strings when the string has spaces.
---
src/json.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/json.c b/src/json.c
index 58af609..78c244c 100644
--- a/src/json.c
+++ b/src/json.c
@@ -58,7 +58,8 @@ char const * bear_json_escape_string(char const * raw)
return 0;
}
- char * const result = malloc(length + ((0 != spaces) * 4) + json + 1);
+ char * const result = malloc(length + ((0 != spaces) * 4)
+ + ((0 != spaces) * 2 * json) + json + 1);
if (0 == result)
{
perror("bear: malloc");
@@ -74,6 +75,11 @@ char const * bear_json_escape_string(char const * raw)
{
if (needs_escape(*raw))
{
+ if (spaces)
+ {
+ *it++ = '\\';
+ *it++ = '\\';
+ }
*it++ = '\\';
}
*it++ = isspace(*raw) ? ' ' : *raw;
--
2.1.4
Set clang++ compiler as default compiler:
$ export CXX=clang++
Generate compilation databases using the given Makefile with Bear and using
cmake:
$ ./gen-databases.sh
Use any clang tooling standalone program, eg clang-tidy.
It success with the database generated by cmake, but fails when use the
database created by Bear:
$ clang-tidy -p build hello.cxx # success with cmake
$ clang-tidy hello.cxx # fail with Bear
3 errors generated.
Error while processing /home/jmpc/jumapico/bug-bear/hello.cxx.
hello.cxx:3:1: error: unknown type name 'C' [clang-diagnostic-error]
EXPORT void foo(void) {
^
note: expanded from here
hello.cxx:3:8: error: expected unqualified-id [clang-diagnostic-error]
EXPORT void foo(void) {
^
hello.cxx:8:3: error: use of undeclared identifier 'foo' [clang-diagnostic-error]
foo();
^
cmake_minimum_required (VERSION 2.8)
add_definitions(-DEXPORT=extern\ "C")
add_executable(hello hello.cxx)
#!/bin/bash
# Generate cmake compilation database
rm -fr build
mkdir build
pushd build
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
make
popd
# Generate bear compilation database
make clean
bear make
#include <cstdio>
EXPORT void foo(void) {
printf("Hello world!\n");
}
int main() {
foo();
}
hello:
$(CXX) -DEXPORT="extern \"C\"" -o hello hello.cxx
clean:
rm -f hello compile_commands.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment