fix: move struct fc_slot definition to slot.h and declare accessors to fix 64-bit pointer truncation

The struct fc_slot was defined only in slot.c, making it an incomplete type
in slot.h. The inline accessor functions (fc_slot_id, fc_slot_header, etc.)
in slot.h could not compile because they referenced incomplete struct
members. The compiler fell back to implicit int return type, truncating
64-bit pointers to 32 bits, causing SIGSEGV in registry_add() when
strncpy received a truncated slot_id pointer.

Fix: move the struct definition to slot.h and add proper function
declarations for the accessors (definitions stay in slot.c).
This commit is contained in:
Wild Dragon Dev 2026-06-03 20:10:31 +00:00
parent 902d985ca8
commit f318e9c501
2 changed files with 17 additions and 17 deletions

View file

@ -17,17 +17,6 @@
#define SEM_PREFIX "/framecache-"
#define SEM_SUFFIX "-write"
/* Internal handle used by both server (writer) and client (reader) */
struct fc_slot {
int shm_fd;
void *base;
size_t shm_size;
sem_t *sem;
char slot_id[FC_MAX_SLOT_ID];
char shm_path[128];
char sem_name[128];
};
/* ── helpers ─────────────────────────────────────────────────────────── */
static void build_paths(const char *slot_id,
@ -172,12 +161,6 @@ void fc_slot_write_frame(struct fc_slot *s,
sem_post(s->sem);
}
/* Accessors used by HTTP API */
fc_header_t *fc_slot_header(struct fc_slot *s) { return (fc_header_t *)s->base; }
const char *fc_slot_id(struct fc_slot *s) { return s->slot_id; }
const char *fc_slot_shm_path(struct fc_slot *s) { return s->shm_path; }
const char *fc_slot_sem_name(struct fc_slot *s) { return s->sem_name; }
/* ── client-side open / read / close (also used by capture-manager) ── */
/**

View file

@ -21,6 +21,17 @@
#define FC_FRAME_HDR_SIZE 24u /* pts_us(8) + wall_us(8) + size(4) + pad(4) */
#define FC_MAX_SLOT_ID 64u
/* Internal handle used by both server (writer) and client (reader) */
struct fc_slot {
int shm_fd;
void *base;
size_t shm_size;
sem_t *sem;
char slot_id[FC_MAX_SLOT_ID];
char shm_path[128];
char sem_name[128];
};
/* Pixel format codes */
#define FC_PIX_UYVY422 0u
@ -57,6 +68,12 @@ typedef struct {
_Static_assert(sizeof(fc_frame_t) == FC_FRAME_HDR_SIZE,
"fc_frame_t header must be exactly FC_FRAME_HDR_SIZE bytes");
/* Accessor function declarations (implemented in slot.c) */
fc_header_t *fc_slot_header(struct fc_slot *s);
const char *fc_slot_id(struct fc_slot *s);
const char *fc_slot_shm_path(struct fc_slot *s);
const char *fc_slot_sem_name(struct fc_slot *s);
/**
* Compute total shm size for a slot given frame_size.
* = FC_HEADER_SIZE + ring_depth * (FC_FRAME_HDR_SIZE + frame_size)