A couple of fixes found by the clang static analyzer.
* maint:
aft: Check return value of load_afsi().
audiod: Avoid reading garbage in get_time_string().
net: Always initialize struct sockaddr_storage.
wma_afh: Fix two bugs in convert_utf8_to_utf16().
ret = get_afsi_object_of_row(row, &target_afsi_obj);
if (ret < 0)
return ret;
- load_afsi(&target_afsi, &target_afsi_obj);
+ ret = load_afsi(&target_afsi, &target_afsi_obj);
+ if (ret < 0)
+ return ret;
old_afsi = target_afsi;
if (cad->flags & CPSI_FLAG_COPY_LYRICS_ID)
target_afsi.lyrics_id = cad->source_afsi.lyrics_id;
rskip; /* receiver start - sss */
int slot_num = get_play_time_slot_num();
struct slot_info *s = slot_num < 0? NULL : &slot[slot_num];
+ bool writer_active = s && s->wns && s->wns[0].btrn;
char *msg;
if (audiod_status == AUDIOD_OFF)
}
/*
* Valid status items and playing, set length and tmp to the stream
- * start. We use the slot info and fall back to the info from current
- * status items if no slot info is available.
+ * start. We use the writer start time from the slot info and fall back
+ * to the info from current status items if no writer is active yet.
*/
tmp = &stat_task->server_stream_start;
- if (s && s->wns && s->wns[0].btrn) { /* writer active in this slot */
+ if (writer_active) {
btr_get_node_start(s->wns[0].btrn, &wstime);
if (wstime.tv_sec != 0) { /* writer wrote something */
if (s->server_stream_start.tv_sec == 0) {
tv_diff(tmp, &stat_task->sa_time_diff, &sss);
else
tv_add(tmp, &stat_task->sa_time_diff, &sss);
- if (!s || !s->wns || !s->wns[0].btrn || wstime.tv_sec == 0) {
+ if (!writer_active) {
struct timeval diff;
tv_diff(now, &sss, &diff);
seconds = diff.tv_sec + stat_task->offset_seconds;
*/
int generic_max_transport_msg_size(int sockfd)
{
- struct sockaddr_storage ss;
+ struct sockaddr_storage ss = {0};
socklen_t sslen = sizeof(ss);
int af_type = AF_INET;
*/
char *remote_name(int fd)
{
- struct sockaddr_storage ss;
+ struct sockaddr_storage ss = {0};
const struct sockaddr *sa;
socklen_t sslen = sizeof(ss);
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
static int convert_utf8_to_utf16(char *src, char **dst)
{
- /*
- * Without specifying LE (little endian), iconv includes a byte order
- * mark (e.g. 0xFFFE) at the beginning.
- */
- iconv_t cd = iconv_open("UTF-16LE", "UTF-8");
+ iconv_t cd;
size_t sz, inbytes, outbytes, inbytesleft, outbytesleft;
char *inbuf, *outbuf;
int ret;
if (!src || !*src) {
*dst = para_calloc(2);
- ret = 0;
- goto out;
+ return 0;
}
- if (cd == (iconv_t) -1)
+ /*
+ * Without specifying LE (little endian), iconv includes a byte order
+ * mark (e.g. 0xFFFE) at the beginning.
+ */
+ cd = iconv_open("UTF-16LE", "UTF-8");
+ if (cd == (iconv_t)-1) {
+ *dst = NULL;
return -ERRNO_TO_PARA_ERROR(errno);
+ }
inbuf = src;
/* even though src is in UTF-8, strlen() should DTRT */
inbytes = inbytesleft = strlen(src);
sz = iconv(cd, ICONV_CAST &inbuf, &inbytesleft, &outbuf, &outbytesleft);
if (sz == (size_t)-1) {
ret = -ERRNO_TO_PARA_ERROR(errno);
+ free(*dst);
+ *dst = NULL;
goto out;
}
assert(outbytes >= outbytesleft);
*dst = outbuf;
PARA_INFO_LOG("converted %s to %d UTF-16 bytes\n", src, ret);
out:
- if (ret < 0)
- free(*dst);
if (iconv_close(cd) < 0)
PARA_WARNING_LOG("iconv_close: %s\n", strerror(errno));
return ret;