Skip to content

Commit e821268

Browse files
committed
decklink_drift_fix: fix allocation
Since the assertion added in 54097db (May 26 2026), msg_universal constructor doesn't set the magic value, resulting in abort. Removed the constructor and replaced with a function utilizing new_message() that is correctly setting this field. fixes GH-497
1 parent 9f53bc1 commit e821268

3 files changed

Lines changed: 24 additions & 12 deletions

File tree

src/messaging.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,16 @@ struct message *new_message(size_t len)
331331
return ret;
332332
}
333333

334+
struct msg_universal *
335+
new_message_universal(const char *contents)
336+
{
337+
struct msg_universal *msg = nullptr;
338+
struct message *m = new_message(sizeof *msg);
339+
msg = (struct msg_universal *) m;
340+
strcpy_ch(msg->text, contents);
341+
return msg;
342+
}
343+
334344
/**
335345
* Frees message
336346
*

src/messaging.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ struct response;
6767

6868
#define RESPONSE_SUCCESSFUL(code) ((code) >= 200 && (code) < 300)
6969

70-
struct message;
71-
70+
/// message must be allocated with dedicated function - new_message() or
71+
/// new_message_universal()
7272
struct message {
7373
alignas(8) uint32_t magic;
7474
/**
@@ -148,18 +148,17 @@ struct msg_stats {
148148
* msg_universal::text to identify the receiving module.
149149
*/
150150
struct msg_universal {
151-
#ifdef __cplusplus
152-
msg_universal(const char *contents) {
153-
memset(&m, 0, sizeof m);
154-
strncpy(text, contents, sizeof text - 1);
155-
}
156-
#endif
157151
struct message m;
158152
char text[8192];
159153
};
160154

161155
#define MSG_UNIVERSAL_TAG_TX "TX_msg "
162156

157+
/// allocate new message
158+
struct message *new_message(size_t length);
159+
struct msg_universal *new_message_universal(const char *contents);
160+
void free_message(struct message *m, struct response *r);
161+
163162
struct response *new_response(int status, const char *optional_message);
164163
void free_response(struct response *r);
165164
int response_get_status(struct response *r);
@@ -173,8 +172,6 @@ struct response *send_message(struct module *, const char *path, struct message
173172
#define SEND_MESSAGE_FLAG_NO_STORE (1<<1) ///< if receiver doesn't exist, doesn't store it and return 404 instead
174173
struct response *send_message_sync(struct module *, const char *path, struct message *msg, int timeout_ms, int flags) __attribute__ ((warn_unused_result));
175174
struct response *send_message_to_receiver(struct module *, struct message *msg) __attribute__ ((warn_unused_result));
176-
struct message *new_message(size_t length) __attribute__ ((warn_unused_result));
177-
void free_message(struct message *m, struct response *r);
178175
const char *response_status_to_text(int status);
179176

180177
struct message *check_message(struct module *);

src/video_display/decklink_drift_fix.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @author Andrew Walker <andrew.walker@sohonet.com>
55
*/
66
/*
7-
* Copyright (c) 2021-2023 CESNET, z. s. p. o.
7+
* Copyright (c) 2021-2026 CESNET, zájmové sdružení právnických osob
88
* All rights reserved.
99
*
1010
* Redistribution and use in source and binary forms, with or without
@@ -50,6 +50,7 @@
5050
#include "messaging.h"
5151
#include "rtp/audio_decoders.h"
5252
#include "utils/color_out.h"
53+
#include "utils/macros.h" // for snprintf_ch
5354

5455
#define MAX_RESAMPLE_DELTA_DEFAULT 30
5556
#define MIN_RESAMPLE_DELTA_DEFAULT 1
@@ -442,7 +443,11 @@ class AudioDriftFixer {
442443

443444
if (dst_frame_rate != 0 &&
444445
dst_frame_rate != dst_frame_rate_set) {
445-
auto *m = new msg_universal((std::string(MSG_UNIVERSAL_TAG_AUDIO_DECODER) + std::to_string(dst_frame_rate << ADEC_CH_RATE_SHIFT | BASE)).c_str());
446+
char text[128];
447+
snprintf_ch(
448+
text, MSG_UNIVERSAL_TAG_AUDIO_DECODER "%lld",
449+
dst_frame_rate << ADEC_CH_RATE_SHIFT | BASE);
450+
auto *m = new_message_universal(text);
446451
LOG(LOG_LEVEL_DEBUG)
447452
<< MOD_NAME "Sending resample request "
448453
<< dst_frame_rate << "/" << BASE << "\n";

0 commit comments

Comments
 (0)