[FFmpeg-devel] [PATCH v2] Let clang-FORTIFY build; NFC.
George Burgess IV
gbiv at chromium.org
Wed Aug 31 01:49:04 EEST 2016
ChromeOS is adopting a new FORTIFY implementation tailored for clang. As
an artifact of how this new FORTIFY is implemented, a handful of
implicit conversion warnings get turned into errors. This patch fixes
the implicit conversions in ffmpeg that clang-FORTIFY has an issue with.
Signed-off-by: George Burgess IV <gbiv at chromium.org>
---
If anyone feels that more comments would be useful, I'll add them above some of
the char* casts, so it's a bit more obvious why we have said casts.
Testing methodology was "run `make fate` and see what doesn't build." If there
are other targets that would be good to try, I'm happy to check with those, as
well. :)
libavcodec/pamenc.c | 2 +-
libavcodec/pnmenc.c | 4 ++--
libavcodec/xbmenc.c | 8 +++++---
libavcodec/xsubenc.c | 2 +-
libavfilter/af_astats.c | 4 ++--
libavfilter/avf_aphasemeter.c | 2 +-
libavformat/flacenc.c | 2 +-
libavformat/http.c | 4 ++--
libavformat/matroskaenc.c | 3 ++-
libavformat/md5proto.c | 3 ++-
libavformat/nutenc.c | 4 ++--
libavformat/rtmppkt.c | 4 ++--
libavutil/hash.c | 2 +-
libavutil/opt.c | 5 +++--
14 files changed, 27 insertions(+), 22 deletions(-)
diff --git a/libavcodec/pamenc.c b/libavcodec/pamenc.c
index 50c9fcb..143d38f 100644
--- a/libavcodec/pamenc.c
+++ b/libavcodec/pamenc.c
@@ -98,7 +98,7 @@ static int pam_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
bytestream = pkt->data;
bytestream_end = pkt->data + pkt->size;
- snprintf(bytestream, bytestream_end - bytestream,
+ snprintf((char *)bytestream, bytestream_end - bytestream,
"P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\nTUPLTYPE %s\nENDHDR\n",
w, h, depth, maxval, tuple_type);
bytestream += strlen(bytestream);
diff --git a/libavcodec/pnmenc.c b/libavcodec/pnmenc.c
index ba9478d..f1bcbc6 100644
--- a/libavcodec/pnmenc.c
+++ b/libavcodec/pnmenc.c
@@ -80,12 +80,12 @@ static int pnm_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
default:
return -1;
}
- snprintf(bytestream, bytestream_end - bytestream,
+ snprintf((char *)bytestream, bytestream_end - bytestream,
"P%c\n%d %d\n", c, avctx->width, h1);
bytestream += strlen(bytestream);
if (avctx->pix_fmt != AV_PIX_FMT_MONOWHITE) {
int maxdepth = (1 << av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth) - 1;
- snprintf(bytestream, bytestream_end - bytestream,
+ snprintf((char *)bytestream, bytestream_end - bytestream,
"%d\n", maxdepth);
bytestream += strlen(bytestream);
}
diff --git a/libavcodec/xbmenc.c b/libavcodec/xbmenc.c
index b25615f..7f7fbc0 100644
--- a/libavcodec/xbmenc.c
+++ b/libavcodec/xbmenc.c
@@ -28,14 +28,16 @@ static int xbm_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *p, int *got_packet)
{
int i, j, ret, size, linesize;
- uint8_t *ptr, *buf;
+ // buf is a char* instead of a uint8_t* to make FORTIFY on clang happy.
+ char *buf;
+ uint8_t *ptr;
linesize = (avctx->width + 7) / 8;
size = avctx->height * (linesize * 7 + 2) + 110;
if ((ret = ff_alloc_packet2(avctx, pkt, size, 0)) < 0)
return ret;
- buf = pkt->data;
+ buf = (char *)pkt->data;
ptr = p->data[0];
buf += snprintf(buf, 32, "#define image_width %u\n", avctx->width);
@@ -49,7 +51,7 @@ static int xbm_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
}
buf += snprintf(buf, 5, " };\n");
- pkt->size = buf - pkt->data;
+ pkt->size = (uint8_t *)buf - pkt->data;
pkt->flags |= AV_PKT_FLAG_KEY;
*got_packet = 1;
return 0;
diff --git a/libavcodec/xsubenc.c b/libavcodec/xsubenc.c
index b3da909..a4a8221 100644
--- a/libavcodec/xsubenc.c
+++ b/libavcodec/xsubenc.c
@@ -163,7 +163,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
return -1;
}
- snprintf(buf, 28,
+ snprintf((char *)buf, 28,
"[%02d:%02d:%02d.%03d-%02d:%02d:%02d.%03d]",
start_tc[3], start_tc[2], start_tc[1], start_tc[0],
end_tc[3], end_tc[2], end_tc[1], end_tc[0]);
diff --git a/libavfilter/af_astats.c b/libavfilter/af_astats.c
index e7f9675..32c6041 100644
--- a/libavfilter/af_astats.c
+++ b/libavfilter/af_astats.c
@@ -211,8 +211,8 @@ static inline void update_stat(AudioStatsContext *s, ChannelStats *p, double d,
static void set_meta(AVDictionary **metadata, int chan, const char *key,
const char *fmt, double val)
{
- uint8_t value[128];
- uint8_t key2[128];
+ char value[128];
+ char key2[128];
snprintf(value, sizeof(value), fmt, val);
if (chan)
diff --git a/libavfilter/avf_aphasemeter.c b/libavfilter/avf_aphasemeter.c
index 8e8b292..4afc6bb 100644
--- a/libavfilter/avf_aphasemeter.c
+++ b/libavfilter/avf_aphasemeter.c
@@ -190,7 +190,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
metadata = avpriv_frame_get_metadatap(out);
if (metadata) {
- uint8_t value[128];
+ char value[128];
snprintf(value, sizeof(value), "%f", fphase);
av_dict_set(metadata, "lavfi.aphasemeter.phase", value, 0);
diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
index 89b21e9..8ef4292 100644
--- a/libavformat/flacenc.c
+++ b/libavformat/flacenc.c
@@ -115,7 +115,7 @@ static int flac_write_header(struct AVFormatContext *s)
av_log(s, AV_LOG_WARNING, "A WAVEFORMATEXTENSIBLE_CHANNEL_MASK is "
"already present, this muxer will not overwrite it.\n");
} else {
- uint8_t buf[32];
+ char buf[32];
snprintf(buf, sizeof(buf), "0x%"PRIx64, par->channel_layout);
av_dict_set(&s->metadata, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", buf, 0);
}
diff --git a/libavformat/http.c b/libavformat/http.c
index adb3d92..282310b 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -1095,7 +1095,7 @@ static int http_connect(URLContext *h, const char *path, const char *local_path,
if (s->headers)
av_strlcpy(headers + len, s->headers, sizeof(headers) - len);
- snprintf(s->buffer, sizeof(s->buffer),
+ snprintf((char *)s->buffer, sizeof(s->buffer),
"%s %s HTTP/1.1\r\n"
"%s"
"%s"
@@ -1593,7 +1593,7 @@ redo:
authstr = ff_http_auth_create_response(&s->proxy_auth_state, auth,
path, "CONNECT");
- snprintf(s->buffer, sizeof(s->buffer),
+ snprintf((char *)s->buffer, sizeof(s->buffer),
"CONNECT %s HTTP/1.1\r\n"
"Host: %s\r\n"
"Connection: close\r\n"
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 2a2877f..2788ff7 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -576,7 +576,8 @@ static int put_flac_codecpriv(AVFormatContext *s,
const char *vendor = (s->flags & AVFMT_FLAG_BITEXACT) ?
"Lavf" : LIBAVFORMAT_IDENT;
AVDictionary *dict = NULL;
- uint8_t buf[32], *data, *p;
+ char buf[32];
+ uint8_t *data, *p;
int64_t len;
snprintf(buf, sizeof(buf), "0x%"PRIx64, par->channel_layout);
diff --git a/libavformat/md5proto.c b/libavformat/md5proto.c
index 0e04b90..23a067a 100644
--- a/libavformat/md5proto.c
+++ b/libavformat/md5proto.c
@@ -57,7 +57,8 @@ static int md5_close(URLContext *h)
{
struct MD5Context *c = h->priv_data;
const char *filename = h->filename;
- uint8_t md5[16], buf[64];
+ uint8_t md5[16];
+ char buf[64];
URLContext *out;
int i, err = 0;
diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index 9e422e1..d698711 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -533,7 +533,7 @@ static int write_streaminfo(NUTContext *nut, AVIOContext *bc, int stream_id) {
count += add_info(dyn_bc, "Disposition", ff_nut_dispositions[i].str);
}
if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
- uint8_t buf[256];
+ char buf[256];
if (st->r_frame_rate.num>0 && st->r_frame_rate.den>0)
snprintf(buf, sizeof(buf), "%d/%d", st->r_frame_rate.num, st->r_frame_rate.den);
else
@@ -842,7 +842,7 @@ static int write_sm_data(AVFormatContext *s, AVIOContext *bc, AVPacket *pkt, int
unsigned flags;
AVIOContext *dyn_bc;
int sm_data_count = 0;
- uint8_t tmp[256];
+ char tmp[256];
uint8_t *dyn_buf;
ret = avio_open_dyn_buf(&dyn_bc);
diff --git a/libavformat/rtmppkt.c b/libavformat/rtmppkt.c
index 0d693c2..4856808 100644
--- a/libavformat/rtmppkt.c
+++ b/libavformat/rtmppkt.c
@@ -494,10 +494,10 @@ int ff_amf_get_field_value(const uint8_t *data, const uint8_t *data_end,
if (size == namelen && !memcmp(data-size, name, namelen)) {
switch (*data++) {
case AMF_DATA_TYPE_NUMBER:
- snprintf(dst, dst_size, "%g", av_int2double(AV_RB64(data)));
+ snprintf((char *)dst, dst_size, "%g", av_int2double(AV_RB64(data)));
break;
case AMF_DATA_TYPE_BOOL:
- snprintf(dst, dst_size, "%s", *data ? "true" : "false");
+ snprintf((char *)dst, dst_size, "%s", *data ? "true" : "false");
break;
case AMF_DATA_TYPE_STRING:
len = bytestream_get_be16(&data);
diff --git a/libavutil/hash.c b/libavutil/hash.c
index 7037b0d..27637b7 100644
--- a/libavutil/hash.c
+++ b/libavutil/hash.c
@@ -215,7 +215,7 @@ void av_hash_final_hex(struct AVHashContext *ctx, uint8_t *dst, int size)
av_hash_final(ctx, buf);
for (i = 0; i < FFMIN(rsize, size / 2); i++)
- snprintf(dst + i * 2, size - i * 2, "%02x", buf[i]);
+ snprintf((char *)dst + i * 2, size - i * 2, "%02x", buf[i]);
}
void av_hash_final_b64(struct AVHashContext *ctx, uint8_t *dst, int size)
diff --git a/libavutil/opt.c b/libavutil/opt.c
index cd16bd1..f7f5225 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -733,7 +733,8 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
{
void *dst, *target_obj;
const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
- uint8_t *bin, buf[128];
+ uint8_t *bin;
+ char buf[128];
int len, i, ret;
int64_t i64;
@@ -795,7 +796,7 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
}
bin = *(uint8_t **)dst;
for (i = 0; i < len; i++)
- snprintf(*out_val + i * 2, 3, "%02X", bin[i]);
+ snprintf(*(char **)out_val + i * 2, 3, "%02X", bin[i]);
return 0;
case AV_OPT_TYPE_IMAGE_SIZE:
ret = snprintf(buf, sizeof(buf), "%dx%d", ((int *)dst)[0], ((int *)dst)[1]);
--
2.6.6
More information about the ffmpeg-devel
mailing list