From df5c3851359c6f087e9ff638092ac0cd4d3140e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=B6ssie?= Date: Wed, 11 Apr 2018 20:16:35 +0200 Subject: [PATCH] Use `cJSON_Minify()` and fix missed `const` opportunities --- rtengine/dcp.cc | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/rtengine/dcp.cc b/rtengine/dcp.cc index 20c86ca9f..164c7680e 100644 --- a/rtengine/dcp.cc +++ b/rtengine/dcp.cc @@ -31,6 +31,13 @@ #include "rawimagesource.h" #include "rt_math.h" +namespace rtengine +{ + +extern const Settings* settings; + +} + using namespace rtengine; using namespace rtexif; @@ -408,17 +415,21 @@ std::map getAliases(const Glib::ustring& profile_dir) std::unique_ptr buffer(new char[length + 1]); std::fseek(file.get(), 0, SEEK_SET); - std::fread(buffer.get(), 1, length, file.get()); - buffer[length] = 0; + const std::size_t read = std::fread(buffer.get(), 1, length, file.get()); + buffer[read] = 0; - std::unique_ptr root(cJSON_Parse(buffer.get())); + cJSON_Minify(buffer.get()); + const std::unique_ptr root(cJSON_Parse(buffer.get())); if (!root || !root->child) { + if (settings->verbose) { + std::cout << "Could not parse 'camera_model_aliases.json' file." << std::endl; + } return {}; } std::map res; - for (cJSON* camera = root->child; camera; camera = camera->next) { + for (const cJSON* camera = root->child; camera; camera = camera->next) { if (cJSON_IsArray(camera)) { const std::size_t array_size = cJSON_GetArraySize(camera); for (std::size_t index = 0; index < array_size; ++index) {