Skip to content

Commit 177b92d

Browse files
JackLau1222quink-black
authored andcommitted
avformat/tls_openssl: fix warnings when openssl is lower version
api doc: https://docs.openssl.org/1.0.2/man3/BIO_s_mem In higher versions (openssl 1.0.2 and higher), the function signature is BIO *BIO_new_mem_buf(const void *buf, int len), so passing a const string doesn't cause an warnings. However, in lower versions of OpenSSL, the function signature becomes BIO *BIO_new_mem_buf(void *buf, int len), which leads to warnings. OpenSSL guarantees that it will not modify the string, so it's safe to cast the pem_str to (void *) to avoid this warning. Signed-off-by: Jack Lau <jacklau1222@qq.com> Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
1 parent 64e6f5d commit 177b92d

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

libavformat/tls_openssl.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,11 @@ int ff_ssl_gen_key_cert(char *key_buf, size_t key_sz, char *cert_buf, size_t cer
415415
*/
416416
static EVP_PKEY *pkey_from_pem_string(const char *pem_str, int is_priv)
417417
{
418+
#if OPENSSL_VERSION_NUMBER < 0x10002000L /* OpenSSL 1.0.2 */
419+
BIO *mem = BIO_new_mem_buf((void *)pem_str, -1);
420+
#else
418421
BIO *mem = BIO_new_mem_buf(pem_str, -1);
422+
#endif
419423
if (!mem) {
420424
av_log(NULL, AV_LOG_ERROR, "BIO_new_mem_buf failed\n");
421425
return NULL;
@@ -445,7 +449,11 @@ static EVP_PKEY *pkey_from_pem_string(const char *pem_str, int is_priv)
445449
*/
446450
static X509 *cert_from_pem_string(const char *pem_str)
447451
{
452+
#if OPENSSL_VERSION_NUMBER < 0x10002000L /* OpenSSL 1.0.2 */
453+
BIO *mem = BIO_new_mem_buf((void *)pem_str, -1);
454+
#else
448455
BIO *mem = BIO_new_mem_buf(pem_str, -1);
456+
#endif
449457
if (!mem) {
450458
av_log(NULL, AV_LOG_ERROR, "BIO_new_mem_buf failed\n");
451459
return NULL;

0 commit comments

Comments
 (0)