szaszm commented on a change in pull request #674: Minificpp 1007 - ECU C2 
integration.
URL: https://github.com/apache/nifi-minifi-cpp/pull/674#discussion_r371958945
 
 

 ##########
 File path: nanofi/src/core/string_utils.c
 ##########
 @@ -162,3 +163,87 @@ token_list tokenize_string_tailfile(const char * str, 
char delim) {
     tks.has_non_delimited_token = 0;
     return tks;
 }
+
+void copystr(const char * source, char ** dest) {
+    if (!source || !dest) return;
+    size_t len = strlen(source);
+    char * tmp = (char *)malloc(len + 1);
+    memset(tmp, 0, len + 1);
+    memcpy(tmp, source, len);
+    *dest = tmp;
+}
+
+void copynstr(const char * source, size_t len, char ** dest) {
+    if (!source || !len || !dest) return;
+    size_t source_len = strlen(source);
+    char * tmp;
+    if (source_len <= len) {
+        copystr(source, &tmp);
+    } else {
+        tmp = (char *)malloc(len + 1);
+        memcpy(tmp, source, len);
+        tmp[len] = '\0';
+    }
+    *dest = tmp;
+}
+
+void copynstrd(const char * source, size_t src_len, unsigned char * dest, 
size_t dest_len) {
+    if (!source || !src_len || !dest || !dest_len) return;
+    size_t min_len = MIN(src_len, dest_len);
+    if (src_len == min_len && src_len != dest_len) {
+        memcpy(dest, source, min_len);
+    } else {
+       memcpy(dest, source, min_len - 1);
+    }
+    dest[min_len] = '\0';
+}
+
+
+int str_to_uint(const char * input_str, uint64_t * out) {
+    if (!input_str) {
+        return -1;
+    }
+    errno = 0;
+    *out = (uint64_t)(strtoul(input_str, NULL, 10));
+    if (errno != 0) {
+        return -1;
+    }
+    return 0;
+}
+
+const char * uint_to_str(uint64_t value) {
+    char value_str[21];
+    snprintf(value_str, sizeof(value_str), "%llu", value);
 
 Review comment:
   The `"llu"` format specifier corresponds to `unsigned long long`. For 
`uint64_t`, use `PRIu64` from `inttypes.h`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to