mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-27 15:45:56 -05:00
Merge branch 'chme-string_printf'
This commit is contained in:
commit
b20f3725ad
24
src/misc.c
24
src/misc.c
@ -32,6 +32,7 @@
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <sys/param.h>
|
||||
#ifndef CLOCK_REALTIME
|
||||
@ -286,6 +287,27 @@ safe_strdup(const char *str)
|
||||
return strdup(str);
|
||||
}
|
||||
|
||||
/*
|
||||
* Wrapper function for vasprintf by Intel Corporation
|
||||
* Published under the L-GPL 2.1 licence as part of clr-boot-manager
|
||||
*
|
||||
* https://github.com/clearlinux/clr-boot-manager
|
||||
*/
|
||||
char *
|
||||
safe_asprintf(const char *fmt, ...)
|
||||
{
|
||||
char *ret = NULL;
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
if (vasprintf(&ret, fmt, va) < 0)
|
||||
{
|
||||
DPRINTF(E_FATAL, L_MISC, "Out of memory for safe_asprintf\n");
|
||||
abort();
|
||||
}
|
||||
va_end(va);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* Key/value functions */
|
||||
struct keyval *
|
||||
@ -1132,3 +1154,5 @@ log_fatal_null(int domain, const char *func, int line)
|
||||
DPRINTF(E_FATAL, domain, "%s returned NULL at line %d\n", func, line);
|
||||
abort();
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,6 +50,10 @@ safe_hextou64(const char *str, uint64_t *val);
|
||||
char *
|
||||
safe_strdup(const char *str);
|
||||
|
||||
char *
|
||||
safe_asprintf(const char *fmt, ...);
|
||||
|
||||
|
||||
/* Key/value functions */
|
||||
struct keyval *
|
||||
keyval_alloc(void);
|
||||
|
@ -244,9 +244,9 @@ spotifywebapi_request_next(struct spotify_request *request, const char *uri, boo
|
||||
if (append_market && spotify_user_country)
|
||||
{
|
||||
if (strchr(uri, '?'))
|
||||
asprintf(&next_uri, "%s&market=%s", uri, spotify_user_country);
|
||||
next_uri = safe_asprintf("%s&market=%s", uri, spotify_user_country);
|
||||
else
|
||||
asprintf(&next_uri, "%s?market=%s", uri, spotify_user_country);
|
||||
next_uri = safe_asprintf("%s?market=%s", uri, spotify_user_country);
|
||||
}
|
||||
else
|
||||
next_uri = strdup(uri);
|
||||
|
Loading…
Reference in New Issue
Block a user