mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-21 01:42:18 +00:00
Add 'strlen' argument to strn_fromprint()
This commit is contained in:
parent
e82d22d765
commit
05d4215752
@ -483,7 +483,7 @@ int app_echo(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
DEBUGF("echo:argv[%d]=\"%s\"", i, arg);
|
||||
if (escapes) {
|
||||
unsigned char buf[strlen(arg)];
|
||||
size_t len = strn_fromprint(buf, sizeof buf, arg, '\0', NULL);
|
||||
size_t len = strn_fromprint(buf, sizeof buf, arg, 0, '\0', NULL);
|
||||
cli_write(context, buf, len);
|
||||
} else
|
||||
cli_puts(context, arg);
|
||||
|
@ -675,7 +675,7 @@ static int load_did_name(keypair *kp, const char *text)
|
||||
return WHY("duplicate DID");
|
||||
const char *e = NULL;
|
||||
bzero(kp->private_key, kp->private_key_len);
|
||||
strn_fromprint(kp->private_key, kp->private_key_len, t, '"', &e);
|
||||
strn_fromprint(kp->private_key, kp->private_key_len, t, 0, '"', &e);
|
||||
if (*e != '"')
|
||||
return WHY("malformed DID quoted string");
|
||||
t = e + 1;
|
||||
@ -685,7 +685,7 @@ static int load_did_name(keypair *kp, const char *text)
|
||||
return WHY("duplicate Name");
|
||||
const char *e = NULL;
|
||||
bzero(kp->public_key, kp->public_key_len);
|
||||
strn_fromprint(kp->public_key, kp->public_key_len, t, '"', &e);
|
||||
strn_fromprint(kp->public_key, kp->public_key_len, t, 0, '"', &e);
|
||||
if (*e != '"')
|
||||
return WHY("malformed Name quoted string");
|
||||
t = e + 1;
|
||||
|
7
str.c
7
str.c
@ -446,11 +446,12 @@ size_t toprint_str_len(const char *srcStr, const char quotes[2])
|
||||
return srcStr ? strbuf_count(strbuf_toprint_quoted(strbuf_local(NULL, 0), quotes, srcStr)) : 4;
|
||||
}
|
||||
|
||||
size_t strn_fromprint(unsigned char *dst, size_t dstlen, const char *src, char endquote, const char **afterp)
|
||||
size_t strn_fromprint(unsigned char *dst, size_t dstsiz, const char *src, size_t srclen, char endquote, const char **afterp)
|
||||
{
|
||||
unsigned char *const odst = dst;
|
||||
unsigned char *const edst = dst + dstlen;
|
||||
while (*src && *src != endquote && dst < edst) {
|
||||
unsigned char *const edst = dst + dstsiz;
|
||||
const char *const esrc = srclen ? src + srclen : NULL;
|
||||
while (src < esrc && *src && *src != endquote && dst < edst) {
|
||||
switch (*src) {
|
||||
case '\\':
|
||||
++src;
|
||||
|
2
str.h
2
str.h
@ -98,7 +98,7 @@ char *toprint(char *dstStr, ssize_t dstBufSiz, const char *srcBuf, size_t srcByt
|
||||
char *toprint_str(char *dstStr, ssize_t dstBufSiz, const char *srcStr, const char quotes[2]);
|
||||
size_t toprint_len(const char *srcBuf, size_t srcBytes, const char quotes[2]);
|
||||
size_t toprint_str_len(const char *srcStr, const char quotes[2]);
|
||||
size_t strn_fromprint(unsigned char *dst, size_t dstlen, const char *src, char endquote, const char **afterp);
|
||||
size_t strn_fromprint(unsigned char *dst, size_t dstsiz, const char *src, size_t srclen, char endquote, const char **afterp);
|
||||
|
||||
#define alloca_toprint(dstlen,buf,len) toprint((char *)alloca((dstlen) == -1 ? toprint_len((const char *)(buf),(len), "``") + 1 : (dstlen)), (dstlen), (const char *)(buf), (len), "``")
|
||||
#define alloca_str_toprint_quoted(str, quotes) toprint_str((char *)alloca(toprint_str_len((str), (quotes)) + 1), -1, (str), (quotes))
|
||||
|
Loading…
x
Reference in New Issue
Block a user