Skip to content

Commit 1c4a086

Browse files
committed
Merge remote-tracking branch 'besser82/bugfix/json-c' into 0.15
2 parents 1263ea6 + 02da9c4 commit 1c4a086

9 files changed

Lines changed: 48 additions & 17 deletions

File tree

.travis.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ compiler:
66
- gcc
77
- clang
88

9+
env:
10+
- BUILD_TYPE=Release
11+
- BUILD_TYPE=Debug
12+
- BUILD_TYPE=ASAN
13+
914
arch:
1015
packages:
1116
- cmake
@@ -19,7 +24,7 @@ arch:
1924
- wlc-git
2025
- libcap
2126
script:
22-
- "cmake ."
27+
- "cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE ."
2328
- "make"
2429

2530
script:

CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
99
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
1010
add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-unused-result -Werror)
1111

12+
# Add Address Sanitiezed build type
13+
set(CMAKE_C_FLAGS_ASAN
14+
"${CMAKE_C_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer"
15+
CACHE STRING "Flags used by the C compiler during address sanitizer builds."
16+
FORCE )
17+
mark_as_advanced(
18+
CMAKE_C_FLAGS_ASAN
19+
CMAKE_EXE_LINKER_FLAGS_DEBUG
20+
CMAKE_SHARED_LINKER_FLAGS_DEBUG
21+
)
22+
1223
list(INSERT CMAKE_MODULE_PATH 0
1324
${CMAKE_CURRENT_SOURCE_DIR}/CMake
1425
)

include/sway_json_helper.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef _SWAY_JSON_HELPER_H
2+
#define _SWAY_JSON_HELPER_H
3+
4+
#include <json-c/json.h>
5+
6+
// Macros for checking a specific version.
7+
#define JSON_C_VERSION_013 (13 << 8)
8+
9+
// json-c v0.13 uses size_t for array_list_length().
10+
#if defined(JSON_C_VERSION_NUM) && JSON_C_VERSION_NUM >= JSON_C_VERSION_013
11+
typedef size_t json_ar_len_t;
12+
#else
13+
typedef int json_ar_len_t;
14+
#endif
15+
16+
#endif // _SWAY_JSON_HELPER_H

include/swaygrab/json.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <json-c/json.h>
1+
#include "sway_json_helper.h"
22
#include "wlc/wlc.h"
33

44
void init_json_tree(int socketfd);

sway/ipc-server.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <stdlib.h>
1616
#include <sys/ioctl.h>
1717
#include <fcntl.h>
18-
#include <json-c/json.h>
1918
#include <list.h>
2019
#include <libinput.h>
2120
#ifdef __linux__
@@ -25,6 +24,7 @@ struct ucred {
2524
gid_t gid;
2625
};
2726
#endif
27+
#include "sway_json_helper.h"
2828
#include "sway/ipc-json.h"
2929
#include "sway/ipc-server.h"
3030
#include "sway/security.h"
@@ -724,7 +724,7 @@ void ipc_client_handle_command(struct ipc_client *client) {
724724
}
725725

726726
// parse requested event types
727-
for (int i = 0; i < json_object_array_length(request); i++) {
727+
for (json_ar_len_t i = 0; i < json_object_array_length(request); i++) {
728728
const char *event_type = json_object_get_string(json_object_array_get_idx(request, i));
729729
if (strcmp(event_type, "workspace") == 0) {
730730
client->subscribed_events |= event_mask(IPC_EVENT_WORKSPACE);
@@ -1126,7 +1126,8 @@ static void ipc_event_binding(json_object *sb_obj) {
11261126
sway_log(L_DEBUG, "Sending binding::run event");
11271127
json_object *obj = json_object_new_object();
11281128
json_object_object_add(obj, "change", json_object_new_string("run"));
1129-
json_object_object_add(obj, "binding", sb_obj);
1129+
// sb_obj gets owned by the temporary json_object, too.
1130+
json_object_object_add(obj, "binding", json_object_get(sb_obj));
11301131

11311132
const char *json_string = json_object_to_json_string(obj);
11321133
ipc_send_event(json_string, IPC_EVENT_BINDING);

swaybar/status_line.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#include <stdlib.h>
33
#include <string.h>
44
#include <unistd.h>
5-
#include <json-c/json.h>
65

6+
#include "sway_json_helper.h"
77
#include "swaybar/config.h"
88
#include "swaybar/status_line.h"
99
#include "log.h"
@@ -70,8 +70,7 @@ static void parse_json(struct bar *bar, const char *text) {
7070

7171
bar->status->block_line = create_list();
7272

73-
int i;
74-
for (i = 0; i < json_object_array_length(results); ++i) {
73+
for (json_ar_len_t i = 0; i < json_object_array_length(results); ++i) {
7574
json_object *full_text, *short_text, *color, *min_width, *align, *urgent;
7675
json_object *name, *instance, *separator, *separator_block_width;
7776
json_object *background, *border, *border_top, *border_bottom;

swaygrab/json.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ static json_object *get_focused_container_r(json_object *c) {
5050
} else {
5151
json_object *nodes, *node, *child;
5252
json_object_object_get_ex(c, "nodes", &nodes);
53-
int i;
54-
for (i = 0; i < json_object_array_length(nodes); i++) {
53+
for (json_ar_len_t i = 0; i < json_object_array_length(nodes); i++) {
5554
node = json_object_array_get_idx(nodes, i);
5655

5756
if ((child = get_focused_container_r(node))) {
@@ -60,7 +59,7 @@ static json_object *get_focused_container_r(json_object *c) {
6059
}
6160

6261
json_object_object_get_ex(c, "floating_nodes", &nodes);
63-
for (i = 0; i < json_object_array_length(nodes); i++) {
62+
for (json_ar_len_t i = 0; i < json_object_array_length(nodes); i++) {
6463
node = json_object_array_get_idx(nodes, i);
6564

6665
if ((child = get_focused_container_r(node))) {
@@ -83,7 +82,7 @@ char *get_focused_output() {
8382
if (!outputs) {
8483
sway_abort("Unabled to get focused output. No nodes in tree.");
8584
}
86-
for (int i = 0; i < json_object_array_length(outputs); i++) {
85+
for (json_ar_len_t i = 0; i < json_object_array_length(outputs); i++) {
8786
output = json_object_array_get_idx(outputs, i);
8887

8988
if (get_focused_container_r(output)) {
@@ -131,7 +130,7 @@ json_object *get_output_container(const char *output) {
131130
json_object *outputs, *json_output, *name;
132131
json_object_object_get_ex(tree, "nodes", &outputs);
133132

134-
for (int i = 0; i < json_object_array_length(outputs); i++) {
133+
for (json_ar_len_t i = 0; i < json_object_array_length(outputs); i++) {
135134
json_output = json_object_array_get_idx(outputs, i);
136135
json_object_object_get_ex(json_output, "name", &name);
137136

swaylock/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <xkbcommon/xkbcommon.h>
44
#include <xkbcommon/xkbcommon-names.h>
55
#include <security/pam_appl.h>
6-
#include <json-c/json.h>
76
#include <stdio.h>
87
#include <stdlib.h>
98
#include <string.h>
@@ -14,6 +13,7 @@
1413
#include <signal.h>
1514
#include <stdbool.h>
1615
#include <unistd.h>
16+
#include "sway_json_helper.h"
1717
#include "client/window.h"
1818
#include "client/registry.h"
1919
#include "client/cairo.h"
@@ -583,7 +583,7 @@ int main(int argc, char **argv) {
583583

584584
for (i = 0; i < registry->outputs->length; ++i) {
585585
if (displays_paths[i * 2] != NULL) {
586-
for (int j = 0;; ++j) {
586+
for (json_ar_len_t j = 0;; ++j) {
587587
if (j >= json_object_array_length(json_outputs)) {
588588
sway_log(L_ERROR, "%s is not an extant output", displays_paths[i * 2]);
589589
exit(EXIT_FAILURE);

swaymsg/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <sys/socket.h>
1010
#include <ctype.h>
1111
#include <unistd.h>
12-
#include <json-c/json.h>
12+
#include "sway_json_helper.h"
1313
#include "stringop.h"
1414
#include "ipc-client.h"
1515
#include "readline.h"
@@ -149,7 +149,7 @@ static void pretty_print_version(json_object *v) {
149149
static void pretty_print_clipboard(json_object *v) {
150150
if (success(v, true)) {
151151
if (json_object_is_type(v, json_type_array)) {
152-
for (int i = 0; i < json_object_array_length(v); ++i) {
152+
for (json_ar_len_t i = 0; i < json_object_array_length(v); ++i) {
153153
json_object *o = json_object_array_get_idx(v, i);
154154
printf("%s\n", json_object_get_string(o));
155155
}

0 commit comments

Comments
 (0)