Closed Dushistov closed 2 years ago
I just realized that we carry a stupid fix for that in KOReader, does that sound sensible?
diff --git a/src/sdcv.cpp b/src/sdcv.cpp
index 170ac2f..8e0d4f1 100644
--- a/src/sdcv.cpp
+++ b/src/sdcv.cpp
@@ -186,10 +186,10 @@ try {
}
// add bookname to list
- gchar **p = get_impl(use_dict_list);
- while (*p) {
- order_list.push_back(bookname_to_ifo.at(*p));
- ++p;
+ for (gchar **p = get_impl(use_dict_list); *p != nullptr; ++p) {
+ if (bookname_to_ifo.count(*p) > 0) {
+ order_list.push_back(bookname_to_ifo.at(*p));
+ }
}
} else {
std::string ordering_cfg_file = std::string(g_get_user_config_dir()) + G_DIR_SEPARATOR_S "sdcv_ordering";
@@ -201,7 +201,9 @@ try {
if (ordering_file != nullptr) {
std::string line;
while (stdio_getline(ordering_file, line)) {
- order_list.push_back(bookname_to_ifo.at(line));
+ if (bookname_to_ifo.count(line) > 0) {
+ order_list.push_back(bookname_to_ifo.at(line));
+ }
}
fclose(ordering_file);
}
Possibly slightly more efficient variant (I suck at C++):
diff --git a/src/sdcv.cpp b/src/sdcv.cpp
index 170ac2f..46db492 100644
--- a/src/sdcv.cpp
+++ b/src/sdcv.cpp
@@ -186,10 +186,11 @@ try {
}
// add bookname to list
- gchar **p = get_impl(use_dict_list);
- while (*p) {
- order_list.push_back(bookname_to_ifo.at(*p));
- ++p;
+ for (gchar **p = get_impl(use_dict_list); *p != nullptr; ++p) {
+ auto it = bookname_to_ifo.find(*p);
+ if (it != bookname_to_ifo.end()) {
+ order_list.push_back(it->second);
+ }
}
} else {
std::string ordering_cfg_file = std::string(g_get_user_config_dir()) + G_DIR_SEPARATOR_S "sdcv_ordering";
@@ -201,7 +202,10 @@ try {
if (ordering_file != nullptr) {
std::string line;
while (stdio_getline(ordering_file, line)) {
- order_list.push_back(bookname_to_ifo.at(line));
+ auto it = bookname_to_ifo.find(line);
+ if (it != bookname_to_ifo.end()) {
+ order_list.push_back(it->second);
+ }
}
fclose(ordering_file);
}