aboutsummarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntony Kellermann2018-09-13 13:31:24 -0400
committerAntony Kellermann2018-09-13 13:31:24 -0400
commite18930b85bb3a82cdd3b4958f534a593ef9e0649 (patch)
tree6c47bf664864a6810ed805ad0d3eeb8bf162ae8b
parentd0ba04661685755e2c92fb97dc0f2331dd02b87c (diff)
downloadaur-e18930b85bb3a82cdd3b4958f534a593ef9e0649.tar.gz
Used memset to compensate for strncpy lack of null terminator and removed ref data name search
-rw-r--r--api.c20
-rw-r--r--api.h16
2 files changed, 4 insertions, 32 deletions
diff --git a/api.c b/api.c
index 0f4522c45d06..11c883ce5047 100644
--- a/api.c
+++ b/api.c
@@ -12,6 +12,7 @@ Ref_Data* ref_data_init_length(size_t length) {
pRef_Data->names[i] = malloc(NAME_MAX_LENGTH);
pointer_alloc_check(pRef_Data->symbols[i]);
pointer_alloc_check(pRef_Data->names[i]);
+ memset(pRef_Data->names[i], '\0', NAME_MAX_LENGTH);
}
pRef_Data->length = length;
return pRef_Data;
@@ -526,7 +527,6 @@ void info_store_quote_json(Info* pInfo, const Json* jquote) {
pInfo->pe_ratio = json_object_get_double(json_object_object_get(jquote, "peRatio"));
}
-
void info_store_chart_json(Info* pInfo, const Json* jchart) {
free(pInfo->points);
size_t len = json_object_array_length(jchart);
@@ -699,22 +699,6 @@ int ref_data_get_index_from_symbol_bsearch(const Ref_Data* pRef_Data, const char
return ref_data_get_index_from_symbol_bsearch(pRef_Data, symbol, left, mid - 1);
}
-int ref_data_get_index_from_name_bsearch(const Ref_Data* pRef_Data, const char* name,
- size_t left, size_t right) {
- if (right < left)
- return -1;
-
- size_t mid = left + (right - left) / 2;
- int cmp = strcmp(name, pRef_Data->names[mid]);
- if (cmp == 0)
- return (int) mid;
-
- if (cmp > 0)
- return ref_data_get_index_from_name_bsearch(pRef_Data, name, mid + 1, right);
-
- return ref_data_get_index_from_name_bsearch(pRef_Data, name, left, mid - 1);
-}
-
Info* info_array_find_symbol_recursive(const Info_Array* pInfo_Array, const char* symbol) {
Info* pInfo = NULL;
if (pInfo_Array == NULL)
@@ -784,4 +768,4 @@ void info_array_destroy(Info_Array** phInfo_Array) {
info_destroy(&pInfo_Array->totals);
free(*phInfo_Array);
*phInfo_Array = NULL;
-} \ No newline at end of file
+}
diff --git a/api.h b/api.h
index b1bcedccda98..f03fd20aea10 100644
--- a/api.h
+++ b/api.h
@@ -35,8 +35,8 @@ typedef enum data_level {
#include "utils.h"
typedef struct ref_data {
- char** symbols;
- char** names;
+ char** symbols; // Sorted
+ char** names; // Sorted
size_t length;
} Ref_Data;
@@ -383,18 +383,6 @@ int ref_data_get_index_from_symbol_bsearch(const Ref_Data* pRef_Data, const char
size_t left, size_t right);
/**
- * Recursive binary search function for Ref_Data. Returns the index of the security with the given
- * name.
- * @param pRef_Data the Ref_Data to search
- * @param name name of the security to find
- * @param left left-most index to start search
- * @param right right-most index to start search
- * @return index of security if found, -1 if not found
- */
-int ref_data_get_index_from_name_bsearch(const Ref_Data* pRef_Data, const char* name,
- size_t left, size_t right);
-
-/**
* Recursively searches pInfo_Array and pInfo_Array->peers to find an Info* with the given symbol
* @param pInfo_Array the Info_Array to search
* @param symbol the symbol to find