id
int64
1
36.7k
label
int64
0
1
bug_url
stringlengths
91
134
bug_function
stringlengths
13
72.7k
functions
stringlengths
17
79.2k
34,801
1
https://github.com/openssl/openssl/blob/d303b9d85e1888494785f87ebd9bd233e63564a9/apps/crl2p7.c/#L155
int crl2pkcs7_main(int argc, char **argv) { BIO *in = NULL, *out = NULL; PKCS7 *p7 = NULL; PKCS7_SIGNED *p7s = NULL; STACK_OF(OPENSSL_STRING) *certflst = NULL; STACK_OF(X509) *cert_stack = NULL; STACK_OF(X509_CRL) *crl_stack = NULL; X509_CRL *crl = NULL; char *infile = NULL, *outfile = NULL, *prog, *certfile; int i = 0, informat = FORMAT_PEM, outformat = FORMAT_PEM, ret = 1, nocrl = 0; OPTION_CHOICE o; prog = opt_init(argc, argv, crl2pkcs7_options); while ((o = opt_next()) != OPT_EOF) { switch (o) { case OPT_EOF: case OPT_ERR: opthelp: BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); goto end; case OPT_HELP: opt_help(crl2pkcs7_options); ret = 0; goto end; case OPT_INFORM: if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &informat)) goto opthelp; break; case OPT_OUTFORM: if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &outformat)) goto opthelp; break; case OPT_IN: infile = opt_arg(); break; case OPT_OUT: outfile = opt_arg(); break; case OPT_NOCRL: nocrl = 1; break; case OPT_CERTFILE: if ((certflst == NULL) && (certflst = sk_OPENSSL_STRING_new_null()) == NULL) goto end; if (!sk_OPENSSL_STRING_push(certflst, *(++argv))) { sk_OPENSSL_STRING_free(certflst); goto end; } break; } } argc = opt_num_rest(); argv = opt_rest(); if (!app_load_modules(NULL)) goto end; if (!nocrl) { in = bio_open_default(infile, RB(informat)); if (in == NULL) goto end; if (informat == FORMAT_ASN1) crl = d2i_X509_CRL_bio(in, NULL); else if (informat == FORMAT_PEM) crl = PEM_read_bio_X509_CRL(in, NULL, NULL, NULL); if (crl == NULL) { BIO_printf(bio_err, "unable to load CRL\n"); ERR_print_errors(bio_err); goto end; } } if ((p7 = PKCS7_new()) == NULL) goto end; if ((p7s = PKCS7_SIGNED_new()) == NULL) goto end; p7->type = OBJ_nid2obj(NID_pkcs7_signed); p7->d.sign = p7s; p7s->contents->type = OBJ_nid2obj(NID_pkcs7_data); if (!ASN1_INTEGER_set(p7s->version, 1)) goto end; if ((crl_stack = sk_X509_CRL_new_null()) == NULL) goto end; p7s->crl = crl_stack; if (crl != NULL) { sk_X509_CRL_push(crl_stack, crl); crl = NULL; } if ((cert_stack = sk_X509_new_null()) == NULL) goto end; p7s->cert = cert_stack; if (certflst) for (i = 0; i < sk_OPENSSL_STRING_num(certflst); i++) { certfile = sk_OPENSSL_STRING_value(certflst, i); if (add_certs_from_file(cert_stack, certfile) < 0) { BIO_printf(bio_err, "error loading certificates\n"); ERR_print_errors(bio_err); goto end; } } sk_OPENSSL_STRING_free(certflst); out = bio_open_default(outfile, WB(outformat)); if (out == NULL) goto end; if (outformat == FORMAT_ASN1) i = i2d_PKCS7_bio(out, p7); else if (outformat == FORMAT_PEM) i = PEM_write_bio_PKCS7(out, p7); if (!i) { BIO_printf(bio_err, "unable to write pkcs7 object\n"); ERR_print_errors(bio_err); goto end; } ret = 0; end: BIO_free(in); BIO_free_all(out); PKCS7_free(p7); X509_CRL_free(crl); return (ret); }
['int crl2pkcs7_main(int argc, char **argv)\n{\n BIO *in = NULL, *out = NULL;\n PKCS7 *p7 = NULL;\n PKCS7_SIGNED *p7s = NULL;\n STACK_OF(OPENSSL_STRING) *certflst = NULL;\n STACK_OF(X509) *cert_stack = NULL;\n STACK_OF(X509_CRL) *crl_stack = NULL;\n X509_CRL *crl = NULL;\n char *infile = NULL, *outfile = NULL, *prog, *certfile;\n int i = 0, informat = FORMAT_PEM, outformat = FORMAT_PEM, ret = 1, nocrl =\n 0;\n OPTION_CHOICE o;\n prog = opt_init(argc, argv, crl2pkcs7_options);\n while ((o = opt_next()) != OPT_EOF) {\n switch (o) {\n case OPT_EOF:\n case OPT_ERR:\n opthelp:\n BIO_printf(bio_err, "%s: Use -help for summary.\\n", prog);\n goto end;\n case OPT_HELP:\n opt_help(crl2pkcs7_options);\n ret = 0;\n goto end;\n case OPT_INFORM:\n if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &informat))\n goto opthelp;\n break;\n case OPT_OUTFORM:\n if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &outformat))\n goto opthelp;\n break;\n case OPT_IN:\n infile = opt_arg();\n break;\n case OPT_OUT:\n outfile = opt_arg();\n break;\n case OPT_NOCRL:\n nocrl = 1;\n break;\n case OPT_CERTFILE:\n if ((certflst == NULL)\n && (certflst = sk_OPENSSL_STRING_new_null()) == NULL)\n goto end;\n if (!sk_OPENSSL_STRING_push(certflst, *(++argv))) {\n sk_OPENSSL_STRING_free(certflst);\n goto end;\n }\n break;\n }\n }\n argc = opt_num_rest();\n argv = opt_rest();\n if (!app_load_modules(NULL))\n goto end;\n if (!nocrl) {\n in = bio_open_default(infile, RB(informat));\n if (in == NULL)\n goto end;\n if (informat == FORMAT_ASN1)\n crl = d2i_X509_CRL_bio(in, NULL);\n else if (informat == FORMAT_PEM)\n crl = PEM_read_bio_X509_CRL(in, NULL, NULL, NULL);\n if (crl == NULL) {\n BIO_printf(bio_err, "unable to load CRL\\n");\n ERR_print_errors(bio_err);\n goto end;\n }\n }\n if ((p7 = PKCS7_new()) == NULL)\n goto end;\n if ((p7s = PKCS7_SIGNED_new()) == NULL)\n goto end;\n p7->type = OBJ_nid2obj(NID_pkcs7_signed);\n p7->d.sign = p7s;\n p7s->contents->type = OBJ_nid2obj(NID_pkcs7_data);\n if (!ASN1_INTEGER_set(p7s->version, 1))\n goto end;\n if ((crl_stack = sk_X509_CRL_new_null()) == NULL)\n goto end;\n p7s->crl = crl_stack;\n if (crl != NULL) {\n sk_X509_CRL_push(crl_stack, crl);\n crl = NULL;\n }\n if ((cert_stack = sk_X509_new_null()) == NULL)\n goto end;\n p7s->cert = cert_stack;\n if (certflst)\n for (i = 0; i < sk_OPENSSL_STRING_num(certflst); i++) {\n certfile = sk_OPENSSL_STRING_value(certflst, i);\n if (add_certs_from_file(cert_stack, certfile) < 0) {\n BIO_printf(bio_err, "error loading certificates\\n");\n ERR_print_errors(bio_err);\n goto end;\n }\n }\n sk_OPENSSL_STRING_free(certflst);\n out = bio_open_default(outfile, WB(outformat));\n if (out == NULL)\n goto end;\n if (outformat == FORMAT_ASN1)\n i = i2d_PKCS7_bio(out, p7);\n else if (outformat == FORMAT_PEM)\n i = PEM_write_bio_PKCS7(out, p7);\n if (!i) {\n BIO_printf(bio_err, "unable to write pkcs7 object\\n");\n ERR_print_errors(bio_err);\n goto end;\n }\n ret = 0;\n end:\n BIO_free(in);\n BIO_free_all(out);\n PKCS7_free(p7);\n X509_CRL_free(crl);\n return (ret);\n}', 'int opt_num_rest(void)\n{\n int i = 0;\n char **pp;\n for (pp = opt_rest(); *pp; pp++, i++)\n continue;\n return i;\n}', 'char **opt_rest(void)\n{\n return &argv[opt_index];\n}', 'int app_load_modules(const CONF *config)\n{\n CONF *to_free = NULL;\n if (config == NULL)\n\tconfig = to_free = app_load_config_quiet(default_config_file);\n if (config == NULL)\n\treturn 1;\n if (CONF_modules_load(config, NULL, 0) <= 0) {\n BIO_printf(bio_err, "Error configuring OpenSSL modules\\n");\n ERR_print_errors(bio_err);\n NCONF_free(to_free);\n return 0;\n }\n NCONF_free(to_free);\n return 1;\n}', 'BIO *bio_open_default(const char *filename, const char *mode)\n{\n return bio_open_default_(filename, mode, 0);\n}', 'static BIO *bio_open_default_(const char *filename, const char *mode, int quiet)\n{\n BIO *ret;\n if (filename == NULL || strcmp(filename, "-") == 0) {\n ret = *mode == \'r\' ? dup_bio_in() : dup_bio_out();\n if (quiet) {\n ERR_clear_error();\n return ret;\n }\n if (ret != NULL)\n return ret;\n BIO_printf(bio_err,\n "Can\'t open %s, %s\\n",\n *mode == \'r\' ? "stdin" : "stdout", strerror(errno));\n } else {\n ret = BIO_new_file(filename, mode);\n if (quiet) {\n ERR_clear_error();\n return ret;\n }\n if (ret != NULL)\n return ret;\n BIO_printf(bio_err,\n "Can\'t open %s for %s, %s\\n",\n filename,\n *mode == \'r\' ? "reading" : "writing", strerror(errno));\n }\n ERR_print_errors(bio_err);\n return NULL;\n}', 'BIO *dup_bio_in(void)\n{\n return BIO_new_fp(stdin, BIO_NOCLOSE | BIO_FP_TEXT);\n}']
34,802
0
https://github.com/libav/libav/blob/fc322d6a70189da24dbd445c710bb214eb031ce7/libavcodec/mlpdec.c/#L1205
static int read_access_unit(AVCodecContext *avctx, void* data, int *got_frame_ptr, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; MLPDecodeContext *m = avctx->priv_data; BitstreamContext bc; unsigned int length, substr; unsigned int substream_start; unsigned int header_size = 4; unsigned int substr_header_size = 0; uint8_t substream_parity_present[MAX_SUBSTREAMS]; uint16_t substream_data_len[MAX_SUBSTREAMS]; uint8_t parity_bits; int ret; if (buf_size < 4) return 0; length = (AV_RB16(buf) & 0xfff) * 2; if (length < 4 || length > buf_size) return AVERROR_INVALIDDATA; bitstream_init(&bc, (buf + 4), (length - 4) * 8); m->is_major_sync_unit = 0; if (bitstream_peek(&bc, 31) == (0xf8726fba >> 1)) { if (read_major_sync(m, &bc) < 0) goto error; m->is_major_sync_unit = 1; header_size += m->major_sync_header_size; } if (!m->params_valid) { av_log(m->avctx, AV_LOG_WARNING, "Stream parameters not seen; skipping frame.\n"); *got_frame_ptr = 0; return length; } substream_start = 0; for (substr = 0; substr < m->num_substreams; substr++) { int extraword_present, checkdata_present, end, nonrestart_substr; extraword_present = bitstream_read_bit(&bc); nonrestart_substr = bitstream_read_bit(&bc); checkdata_present = bitstream_read_bit(&bc); bitstream_skip(&bc, 1); end = bitstream_read(&bc, 12) * 2; substr_header_size += 2; if (extraword_present) { if (m->avctx->codec_id == AV_CODEC_ID_MLP) { av_log(m->avctx, AV_LOG_ERROR, "There must be no extraword for MLP.\n"); goto error; } bitstream_skip(&bc, 16); substr_header_size += 2; } if (!(nonrestart_substr ^ m->is_major_sync_unit)) { av_log(m->avctx, AV_LOG_ERROR, "Invalid nonrestart_substr.\n"); goto error; } if (end + header_size + substr_header_size > length) { av_log(m->avctx, AV_LOG_ERROR, "Indicated length of substream %d data goes off end of " "packet.\n", substr); end = length - header_size - substr_header_size; } if (end < substream_start) { av_log(avctx, AV_LOG_ERROR, "Indicated end offset of substream %d data " "is smaller than calculated start offset.\n", substr); goto error; } if (substr > m->max_decoded_substream) continue; substream_parity_present[substr] = checkdata_present; substream_data_len[substr] = end - substream_start; substream_start = end; } parity_bits = ff_mlp_calculate_parity(buf, 4); parity_bits ^= ff_mlp_calculate_parity(buf + header_size, substr_header_size); if ((((parity_bits >> 4) ^ parity_bits) & 0xF) != 0xF) { av_log(avctx, AV_LOG_ERROR, "Parity check failed.\n"); goto error; } buf += header_size + substr_header_size; for (substr = 0; substr <= m->max_decoded_substream; substr++) { SubStream *s = &m->substream[substr]; bitstream_init(&bc, buf, substream_data_len[substr] * 8); m->matrix_changed = 0; memset(m->filter_changed, 0, sizeof(m->filter_changed)); s->blockpos = 0; do { if (bitstream_read_bit(&bc)) { if (bitstream_read_bit(&bc)) { if (read_restart_header(m, &bc, buf, substr) < 0) goto next_substr; s->restart_seen = 1; } if (!s->restart_seen) goto next_substr; if (read_decoding_params(m, &bc, substr) < 0) goto next_substr; } if (!s->restart_seen) goto next_substr; if ((ret = read_block_data(m, &bc, substr)) < 0) return ret; if (bitstream_tell(&bc) >= substream_data_len[substr] * 8) goto substream_length_mismatch; } while (!bitstream_read_bit(&bc)); bitstream_skip(&bc, (-bitstream_tell(&bc)) & 15); if (substream_data_len[substr] * 8 - bitstream_tell(&bc) >= 32) { int shorten_by; if (bitstream_read(&bc, 16) != 0xD234) return AVERROR_INVALIDDATA; shorten_by = bitstream_read(&bc, 16); if (m->avctx->codec_id == AV_CODEC_ID_TRUEHD && shorten_by & 0x2000) s->blockpos -= FFMIN(shorten_by & 0x1FFF, s->blockpos); else if (m->avctx->codec_id == AV_CODEC_ID_MLP && shorten_by != 0xD234) return AVERROR_INVALIDDATA; if (substr == m->max_decoded_substream) av_log(m->avctx, AV_LOG_INFO, "End of stream indicated.\n"); } if (substream_parity_present[substr]) { uint8_t parity, checksum; if (substream_data_len[substr] * 8 - bitstream_tell(&bc) != 16) goto substream_length_mismatch; parity = ff_mlp_calculate_parity(buf, substream_data_len[substr] - 2); checksum = ff_mlp_checksum8 (buf, substream_data_len[substr] - 2); if ((bitstream_read(&bc, 8) ^ parity) != 0xa9) av_log(m->avctx, AV_LOG_ERROR, "Substream %d parity check failed.\n", substr); if (bitstream_read(&bc, 8) != checksum) av_log(m->avctx, AV_LOG_ERROR, "Substream %d checksum failed.\n" , substr); } if (substream_data_len[substr] * 8 != bitstream_tell(&bc)) goto substream_length_mismatch; next_substr: if (!s->restart_seen) av_log(m->avctx, AV_LOG_ERROR, "No restart header present in substream %d.\n", substr); buf += substream_data_len[substr]; } rematrix_channels(m, m->max_decoded_substream); if ((ret = output_data(m, m->max_decoded_substream, data, got_frame_ptr)) < 0) return ret; return length; substream_length_mismatch: av_log(m->avctx, AV_LOG_ERROR, "substream %d length mismatch\n", substr); return AVERROR_INVALIDDATA; error: m->params_valid = 0; return AVERROR_INVALIDDATA; }
['static int read_access_unit(AVCodecContext *avctx, void* data,\n int *got_frame_ptr, AVPacket *avpkt)\n{\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n MLPDecodeContext *m = avctx->priv_data;\n BitstreamContext bc;\n unsigned int length, substr;\n unsigned int substream_start;\n unsigned int header_size = 4;\n unsigned int substr_header_size = 0;\n uint8_t substream_parity_present[MAX_SUBSTREAMS];\n uint16_t substream_data_len[MAX_SUBSTREAMS];\n uint8_t parity_bits;\n int ret;\n if (buf_size < 4)\n return 0;\n length = (AV_RB16(buf) & 0xfff) * 2;\n if (length < 4 || length > buf_size)\n return AVERROR_INVALIDDATA;\n bitstream_init(&bc, (buf + 4), (length - 4) * 8);\n m->is_major_sync_unit = 0;\n if (bitstream_peek(&bc, 31) == (0xf8726fba >> 1)) {\n if (read_major_sync(m, &bc) < 0)\n goto error;\n m->is_major_sync_unit = 1;\n header_size += m->major_sync_header_size;\n }\n if (!m->params_valid) {\n av_log(m->avctx, AV_LOG_WARNING,\n "Stream parameters not seen; skipping frame.\\n");\n *got_frame_ptr = 0;\n return length;\n }\n substream_start = 0;\n for (substr = 0; substr < m->num_substreams; substr++) {\n int extraword_present, checkdata_present, end, nonrestart_substr;\n extraword_present = bitstream_read_bit(&bc);\n nonrestart_substr = bitstream_read_bit(&bc);\n checkdata_present = bitstream_read_bit(&bc);\n bitstream_skip(&bc, 1);\n end = bitstream_read(&bc, 12) * 2;\n substr_header_size += 2;\n if (extraword_present) {\n if (m->avctx->codec_id == AV_CODEC_ID_MLP) {\n av_log(m->avctx, AV_LOG_ERROR, "There must be no extraword for MLP.\\n");\n goto error;\n }\n bitstream_skip(&bc, 16);\n substr_header_size += 2;\n }\n if (!(nonrestart_substr ^ m->is_major_sync_unit)) {\n av_log(m->avctx, AV_LOG_ERROR, "Invalid nonrestart_substr.\\n");\n goto error;\n }\n if (end + header_size + substr_header_size > length) {\n av_log(m->avctx, AV_LOG_ERROR,\n "Indicated length of substream %d data goes off end of "\n "packet.\\n", substr);\n end = length - header_size - substr_header_size;\n }\n if (end < substream_start) {\n av_log(avctx, AV_LOG_ERROR,\n "Indicated end offset of substream %d data "\n "is smaller than calculated start offset.\\n",\n substr);\n goto error;\n }\n if (substr > m->max_decoded_substream)\n continue;\n substream_parity_present[substr] = checkdata_present;\n substream_data_len[substr] = end - substream_start;\n substream_start = end;\n }\n parity_bits = ff_mlp_calculate_parity(buf, 4);\n parity_bits ^= ff_mlp_calculate_parity(buf + header_size, substr_header_size);\n if ((((parity_bits >> 4) ^ parity_bits) & 0xF) != 0xF) {\n av_log(avctx, AV_LOG_ERROR, "Parity check failed.\\n");\n goto error;\n }\n buf += header_size + substr_header_size;\n for (substr = 0; substr <= m->max_decoded_substream; substr++) {\n SubStream *s = &m->substream[substr];\n bitstream_init(&bc, buf, substream_data_len[substr] * 8);\n m->matrix_changed = 0;\n memset(m->filter_changed, 0, sizeof(m->filter_changed));\n s->blockpos = 0;\n do {\n if (bitstream_read_bit(&bc)) {\n if (bitstream_read_bit(&bc)) {\n if (read_restart_header(m, &bc, buf, substr) < 0)\n goto next_substr;\n s->restart_seen = 1;\n }\n if (!s->restart_seen)\n goto next_substr;\n if (read_decoding_params(m, &bc, substr) < 0)\n goto next_substr;\n }\n if (!s->restart_seen)\n goto next_substr;\n if ((ret = read_block_data(m, &bc, substr)) < 0)\n return ret;\n if (bitstream_tell(&bc) >= substream_data_len[substr] * 8)\n goto substream_length_mismatch;\n } while (!bitstream_read_bit(&bc));\n bitstream_skip(&bc, (-bitstream_tell(&bc)) & 15);\n if (substream_data_len[substr] * 8 - bitstream_tell(&bc) >= 32) {\n int shorten_by;\n if (bitstream_read(&bc, 16) != 0xD234)\n return AVERROR_INVALIDDATA;\n shorten_by = bitstream_read(&bc, 16);\n if (m->avctx->codec_id == AV_CODEC_ID_TRUEHD && shorten_by & 0x2000)\n s->blockpos -= FFMIN(shorten_by & 0x1FFF, s->blockpos);\n else if (m->avctx->codec_id == AV_CODEC_ID_MLP && shorten_by != 0xD234)\n return AVERROR_INVALIDDATA;\n if (substr == m->max_decoded_substream)\n av_log(m->avctx, AV_LOG_INFO, "End of stream indicated.\\n");\n }\n if (substream_parity_present[substr]) {\n uint8_t parity, checksum;\n if (substream_data_len[substr] * 8 - bitstream_tell(&bc) != 16)\n goto substream_length_mismatch;\n parity = ff_mlp_calculate_parity(buf, substream_data_len[substr] - 2);\n checksum = ff_mlp_checksum8 (buf, substream_data_len[substr] - 2);\n if ((bitstream_read(&bc, 8) ^ parity) != 0xa9)\n av_log(m->avctx, AV_LOG_ERROR, "Substream %d parity check failed.\\n", substr);\n if (bitstream_read(&bc, 8) != checksum)\n av_log(m->avctx, AV_LOG_ERROR, "Substream %d checksum failed.\\n" , substr);\n }\n if (substream_data_len[substr] * 8 != bitstream_tell(&bc))\n goto substream_length_mismatch;\nnext_substr:\n if (!s->restart_seen)\n av_log(m->avctx, AV_LOG_ERROR,\n "No restart header present in substream %d.\\n", substr);\n buf += substream_data_len[substr];\n }\n rematrix_channels(m, m->max_decoded_substream);\n if ((ret = output_data(m, m->max_decoded_substream, data, got_frame_ptr)) < 0)\n return ret;\n return length;\nsubstream_length_mismatch:\n av_log(m->avctx, AV_LOG_ERROR, "substream %d length mismatch\\n", substr);\n return AVERROR_INVALIDDATA;\nerror:\n m->params_valid = 0;\n return AVERROR_INVALIDDATA;\n}']
34,803
0
https://github.com/openssl/openssl/blob/5b18d3025c1c1d36be8f81f137265b46da58f881/engines/e_4758cca.c/#L631
static int cca_rsa_verify(int type, const unsigned char *m, unsigned int m_len, const unsigned char *sigbuf, unsigned int siglen, const RSA *rsa) { long returnCode; long reasonCode; long lsiglen = siglen; long exitDataLength = 0; unsigned char exitData[8]; long ruleArrayLength = 1; unsigned char ruleArray[8] = "PKCS-1.1"; long keyTokenLength; unsigned char *keyToken = (unsigned char *)RSA_get_ex_data(rsa, hndidx); long length = SSL_SIG_LEN; long keyLength; unsigned char *hashBuffer = NULL; X509_SIG sig; ASN1_TYPE parameter; X509_ALGOR algorithm; ASN1_OCTET_STRING digest; keyTokenLength = *(long *)keyToken; keyToken += sizeof(long); if (type == NID_md5 || type == NID_sha1) { sig.algor = &algorithm; algorithm.algorithm = OBJ_nid2obj(type); if (!algorithm.algorithm) { CCA4758err(CCA4758_F_CCA_RSA_VERIFY, CCA4758_R_UNKNOWN_ALGORITHM_TYPE); return 0; } if (!algorithm.algorithm->length) { CCA4758err(CCA4758_F_CCA_RSA_VERIFY, CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD); return 0; } parameter.type = V_ASN1_NULL; parameter.value.ptr = NULL; algorithm.parameter = &parameter; sig.digest = &digest; sig.digest->data = (unsigned char *)m; sig.digest->length = m_len; length = i2d_X509_SIG(&sig, NULL); } keyLength = RSA_size(rsa); if (length - RSA_PKCS1_PADDING > keyLength) { CCA4758err(CCA4758_F_CCA_RSA_VERIFY, CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL); return 0; } switch (type) { case NID_md5_sha1: if (m_len != SSL_SIG_LEN) { CCA4758err(CCA4758_F_CCA_RSA_VERIFY, CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL); return 0; } hashBuffer = (unsigned char *)m; length = m_len; break; case NID_md5: { unsigned char *ptr; ptr = hashBuffer = OPENSSL_malloc((unsigned int)keyLength + 1); if (!hashBuffer) { CCA4758err(CCA4758_F_CCA_RSA_VERIFY, ERR_R_MALLOC_FAILURE); return 0; } i2d_X509_SIG(&sig, &ptr); } break; case NID_sha1: { unsigned char *ptr; ptr = hashBuffer = OPENSSL_malloc((unsigned int)keyLength + 1); if (!hashBuffer) { CCA4758err(CCA4758_F_CCA_RSA_VERIFY, ERR_R_MALLOC_FAILURE); return 0; } i2d_X509_SIG(&sig, &ptr); } break; default: return 0; } digitalSignatureVerify(&returnCode, &reasonCode, &exitDataLength, exitData, &ruleArrayLength, ruleArray, &keyTokenLength, keyToken, &length, hashBuffer, &lsiglen, (unsigned char *)sigbuf); if (type == NID_sha1 || type == NID_md5) { OPENSSL_cleanse(hashBuffer, keyLength + 1); OPENSSL_free(hashBuffer); } return ((returnCode || reasonCode) ? 0 : 1); }
['static int cca_rsa_verify(int type, const unsigned char *m,\n unsigned int m_len, const unsigned char *sigbuf,\n unsigned int siglen, const RSA *rsa)\n{\n long returnCode;\n long reasonCode;\n long lsiglen = siglen;\n long exitDataLength = 0;\n unsigned char exitData[8];\n long ruleArrayLength = 1;\n unsigned char ruleArray[8] = "PKCS-1.1";\n long keyTokenLength;\n unsigned char *keyToken = (unsigned char *)RSA_get_ex_data(rsa, hndidx);\n long length = SSL_SIG_LEN;\n long keyLength;\n unsigned char *hashBuffer = NULL;\n X509_SIG sig;\n ASN1_TYPE parameter;\n X509_ALGOR algorithm;\n ASN1_OCTET_STRING digest;\n keyTokenLength = *(long *)keyToken;\n keyToken += sizeof(long);\n if (type == NID_md5 || type == NID_sha1) {\n sig.algor = &algorithm;\n algorithm.algorithm = OBJ_nid2obj(type);\n if (!algorithm.algorithm) {\n CCA4758err(CCA4758_F_CCA_RSA_VERIFY,\n CCA4758_R_UNKNOWN_ALGORITHM_TYPE);\n return 0;\n }\n if (!algorithm.algorithm->length) {\n CCA4758err(CCA4758_F_CCA_RSA_VERIFY,\n CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD);\n return 0;\n }\n parameter.type = V_ASN1_NULL;\n parameter.value.ptr = NULL;\n algorithm.parameter = &parameter;\n sig.digest = &digest;\n sig.digest->data = (unsigned char *)m;\n sig.digest->length = m_len;\n length = i2d_X509_SIG(&sig, NULL);\n }\n keyLength = RSA_size(rsa);\n if (length - RSA_PKCS1_PADDING > keyLength) {\n CCA4758err(CCA4758_F_CCA_RSA_VERIFY,\n CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);\n return 0;\n }\n switch (type) {\n case NID_md5_sha1:\n if (m_len != SSL_SIG_LEN) {\n CCA4758err(CCA4758_F_CCA_RSA_VERIFY,\n CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);\n return 0;\n }\n hashBuffer = (unsigned char *)m;\n length = m_len;\n break;\n case NID_md5:\n {\n unsigned char *ptr;\n ptr = hashBuffer = OPENSSL_malloc((unsigned int)keyLength + 1);\n if (!hashBuffer) {\n CCA4758err(CCA4758_F_CCA_RSA_VERIFY, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n i2d_X509_SIG(&sig, &ptr);\n }\n break;\n case NID_sha1:\n {\n unsigned char *ptr;\n ptr = hashBuffer = OPENSSL_malloc((unsigned int)keyLength + 1);\n if (!hashBuffer) {\n CCA4758err(CCA4758_F_CCA_RSA_VERIFY, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n i2d_X509_SIG(&sig, &ptr);\n }\n break;\n default:\n return 0;\n }\n digitalSignatureVerify(&returnCode, &reasonCode, &exitDataLength,\n exitData, &ruleArrayLength, ruleArray,\n &keyTokenLength, keyToken, &length, hashBuffer,\n &lsiglen, (unsigned char *)sigbuf);\n if (type == NID_sha1 || type == NID_md5) {\n OPENSSL_cleanse(hashBuffer, keyLength + 1);\n OPENSSL_free(hashBuffer);\n }\n return ((returnCode || reasonCode) ? 0 : 1);\n}', 'void *RSA_get_ex_data(const RSA *r, int idx)\n{\n return (CRYPTO_get_ex_data(&r->ex_data, idx));\n}', 'void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)\n{\n if (ad->sk == NULL)\n return (0);\n else if (idx >= sk_void_num(ad->sk))\n return (0);\n else\n return (sk_void_value(ad->sk, idx));\n}', 'int sk_num(const _STACK *st)\n{\n if (st == NULL)\n return -1;\n return st->num;\n}', 'void *sk_value(const _STACK *st, int i)\n{\n if (!st || (i < 0) || (i >= st->num))\n return NULL;\n return st->data[i];\n}']
34,804
0
https://github.com/libav/libav/blob/2f99117f6ff24ce5be2abb9e014cb8b86c2aa0e0/libavcodec/bitstream.h/#L139
static inline uint64_t get_val(BitstreamContext *bc, unsigned n) { #ifdef BITSTREAM_READER_LE uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1); bc->bits >>= n; #else uint64_t ret = bc->bits >> (64 - n); bc->bits <<= n; #endif bc->bits_left -= n; return ret; }
['static void svq1_parse_string(BitstreamContext *bc, uint8_t *out)\n{\n uint8_t seed;\n int i;\n out[0] = bitstream_read(bc, 8);\n seed = string_table[out[0]];\n for (i = 1; i <= out[0]; i++) {\n out[i] = bitstream_read(bc, 8) ^ seed;\n seed = string_table[out[i] ^ seed];\n }\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n if (!n)\n return 0;\n if (n > bc->bits_left) {\n refill_32(bc);\n if (bc->bits_left < 32)\n bc->bits_left = n;\n }\n return get_val(bc, n);\n}', 'static inline uint64_t get_val(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);\n bc->bits >>= n;\n#else\n uint64_t ret = bc->bits >> (64 - n);\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n return ret;\n}']
34,805
0
https://github.com/libav/libav/blob/ad1161799e096c4bae885f100f27f886755d479a/libavutil/mem.c/#L373
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size) { void **p = ptr; if (min_size < *size) return; min_size = FFMAX(17 * min_size / 16 + 32, min_size); av_free(*p); *p = av_malloc(min_size); if (!*p) min_size = 0; *size = min_size; }
['void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)\n{\n void **p = ptr;\n if (min_size > SIZE_MAX - FF_INPUT_BUFFER_PADDING_SIZE) {\n av_freep(p);\n *size = 0;\n return;\n }\n av_fast_malloc(p, size, min_size + FF_INPUT_BUFFER_PADDING_SIZE);\n if (*size)\n memset((uint8_t *)*p + min_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);\n}', 'void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)\n{\n void **p = ptr;\n if (min_size < *size)\n return;\n min_size = FFMAX(17 * min_size / 16 + 32, min_size);\n av_free(*p);\n *p = av_malloc(min_size);\n if (!*p)\n min_size = 0;\n *size = min_size;\n}']
34,806
0
https://github.com/libav/libav/blob/a893655bdaa726a82424367b6456d195be12ebbc/libavcodec/wmaenc.c/#L61
static int encode_init(AVCodecContext * avctx){ WMACodecContext *s = avctx->priv_data; int i, flags1, flags2; uint8_t *extradata; s->avctx = avctx; if(avctx->channels > MAX_CHANNELS) { av_log(avctx, AV_LOG_ERROR, "too many channels: got %i, need %i or fewer", avctx->channels, MAX_CHANNELS); return AVERROR(EINVAL); } if (avctx->sample_rate > 48000) { av_log(avctx, AV_LOG_ERROR, "sample rate is too high: %d > 48kHz", avctx->sample_rate); return AVERROR(EINVAL); } if(avctx->bit_rate < 24*1000) { av_log(avctx, AV_LOG_ERROR, "bitrate too low: got %i, need 24000 or higher\n", avctx->bit_rate); return AVERROR(EINVAL); } flags1 = 0; flags2 = 1; if (avctx->codec->id == AV_CODEC_ID_WMAV1) { extradata= av_malloc(4); avctx->extradata_size= 4; AV_WL16(extradata, flags1); AV_WL16(extradata+2, flags2); } else if (avctx->codec->id == AV_CODEC_ID_WMAV2) { extradata= av_mallocz(10); avctx->extradata_size= 10; AV_WL32(extradata, flags1); AV_WL16(extradata+4, flags2); }else assert(0); avctx->extradata= extradata; s->use_exp_vlc = flags2 & 0x0001; s->use_bit_reservoir = flags2 & 0x0002; s->use_variable_block_len = flags2 & 0x0004; if (avctx->channels == 2) s->ms_stereo = 1; ff_wma_init(avctx, flags2); for(i = 0; i < s->nb_block_sizes; i++) ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 0, 1.0); s->block_align = avctx->bit_rate * (int64_t)s->frame_len / (avctx->sample_rate * 8); s->block_align = FFMIN(s->block_align, MAX_CODED_SUPERFRAME_SIZE); avctx->block_align = s->block_align; avctx->bit_rate = avctx->block_align * 8LL * avctx->sample_rate / s->frame_len; avctx->frame_size = avctx->delay = s->frame_len; #if FF_API_OLD_ENCODE_AUDIO avctx->coded_frame = &s->frame; avcodec_get_frame_defaults(avctx->coded_frame); #endif return 0; }
['static int encode_init(AVCodecContext * avctx){\n WMACodecContext *s = avctx->priv_data;\n int i, flags1, flags2;\n uint8_t *extradata;\n s->avctx = avctx;\n if(avctx->channels > MAX_CHANNELS) {\n av_log(avctx, AV_LOG_ERROR, "too many channels: got %i, need %i or fewer",\n avctx->channels, MAX_CHANNELS);\n return AVERROR(EINVAL);\n }\n if (avctx->sample_rate > 48000) {\n av_log(avctx, AV_LOG_ERROR, "sample rate is too high: %d > 48kHz",\n avctx->sample_rate);\n return AVERROR(EINVAL);\n }\n if(avctx->bit_rate < 24*1000) {\n av_log(avctx, AV_LOG_ERROR, "bitrate too low: got %i, need 24000 or higher\\n",\n avctx->bit_rate);\n return AVERROR(EINVAL);\n }\n flags1 = 0;\n flags2 = 1;\n if (avctx->codec->id == AV_CODEC_ID_WMAV1) {\n extradata= av_malloc(4);\n avctx->extradata_size= 4;\n AV_WL16(extradata, flags1);\n AV_WL16(extradata+2, flags2);\n } else if (avctx->codec->id == AV_CODEC_ID_WMAV2) {\n extradata= av_mallocz(10);\n avctx->extradata_size= 10;\n AV_WL32(extradata, flags1);\n AV_WL16(extradata+4, flags2);\n }else\n assert(0);\n avctx->extradata= extradata;\n s->use_exp_vlc = flags2 & 0x0001;\n s->use_bit_reservoir = flags2 & 0x0002;\n s->use_variable_block_len = flags2 & 0x0004;\n if (avctx->channels == 2)\n s->ms_stereo = 1;\n ff_wma_init(avctx, flags2);\n for(i = 0; i < s->nb_block_sizes; i++)\n ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 0, 1.0);\n s->block_align = avctx->bit_rate * (int64_t)s->frame_len /\n (avctx->sample_rate * 8);\n s->block_align = FFMIN(s->block_align, MAX_CODED_SUPERFRAME_SIZE);\n avctx->block_align = s->block_align;\n avctx->bit_rate = avctx->block_align * 8LL * avctx->sample_rate /\n s->frame_len;\n avctx->frame_size = avctx->delay = s->frame_len;\n#if FF_API_OLD_ENCODE_AUDIO\n avctx->coded_frame = &s->frame;\n avcodec_get_frame_defaults(avctx->coded_frame);\n#endif\n return 0;\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if (size > (INT_MAX - 32) || !size)\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size + 32);\n if (!ptr)\n return ptr;\n diff = ((-(long)ptr - 1) & 31) + 1;\n ptr = (char *)ptr + diff;\n ((char *)ptr)[-1] = diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr, 32, size))\n ptr = NULL;\n#elif HAVE_ALIGNED_MALLOC\n ptr = _aligned_malloc(size, 32);\n#elif HAVE_MEMALIGN\n ptr = memalign(32, size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
34,807
0
https://github.com/libav/libav/blob/6a2176aac05e1edbcdf8fb9c26d572d092a00c3c/libavcodec/h264.c/#L348
static void await_references(H264Context *h){ MpegEncContext * const s = &h->s; const int mb_xy= h->mb_xy; const int mb_type= s->current_picture.mb_type[mb_xy]; int refs[2][48]; int nrefs[2] = {0}; int ref, list; memset(refs, -1, sizeof(refs)); if(IS_16X16(mb_type)){ get_lowest_part_y(h, refs, 0, 16, 0, IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs); }else if(IS_16X8(mb_type)){ get_lowest_part_y(h, refs, 0, 8, 0, IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs); get_lowest_part_y(h, refs, 8, 8, 8, IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs); }else if(IS_8X16(mb_type)){ get_lowest_part_y(h, refs, 0, 16, 0, IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs); get_lowest_part_y(h, refs, 4, 16, 0, IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs); }else{ int i; assert(IS_8X8(mb_type)); for(i=0; i<4; i++){ const int sub_mb_type= h->sub_mb_type[i]; const int n= 4*i; int y_offset= (i&2)<<2; if(IS_SUB_8X8(sub_mb_type)){ get_lowest_part_y(h, refs, n , 8, y_offset, IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); }else if(IS_SUB_8X4(sub_mb_type)){ get_lowest_part_y(h, refs, n , 4, y_offset, IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); get_lowest_part_y(h, refs, n+2, 4, y_offset+4, IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); }else if(IS_SUB_4X8(sub_mb_type)){ get_lowest_part_y(h, refs, n , 8, y_offset, IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); get_lowest_part_y(h, refs, n+1, 8, y_offset, IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); }else{ int j; assert(IS_SUB_4X4(sub_mb_type)); for(j=0; j<4; j++){ int sub_y_offset= y_offset + 2*(j&2); get_lowest_part_y(h, refs, n+j, 4, sub_y_offset, IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); } } } } for(list=h->list_count-1; list>=0; list--){ for(ref=0; ref<48 && nrefs[list]; ref++){ int row = refs[list][ref]; if(row >= 0){ Picture *ref_pic = &h->ref_list[list][ref]; int ref_field = ref_pic->reference - 1; int ref_field_picture = ref_pic->field_picture; int pic_height = 16*s->mb_height >> ref_field_picture; row <<= MB_MBAFF; nrefs[list]--; if(!FIELD_PICTURE && ref_field_picture){ ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1) - !(row&1), pic_height-1), 1); ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1) , pic_height-1), 0); }else if(FIELD_PICTURE && !ref_field_picture){ ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row*2 + ref_field , pic_height-1), 0); }else if(FIELD_PICTURE){ ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), ref_field); }else{ ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), 0); } } } } }
['static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){\n MpegEncContext * const s = &h->s;\n AVCodecContext * const avctx= s->avctx;\n H264Context *hx;\n int buf_index;\n int context_count;\n int next_avc;\n int pass = !(avctx->active_thread_type & FF_THREAD_FRAME);\n int nals_needed=0;\n int nal_index;\n h->max_contexts = (HAVE_THREADS && (s->avctx->active_thread_type&FF_THREAD_SLICE)) ? avctx->thread_count : 1;\n if(!(s->flags2 & CODEC_FLAG2_CHUNKS)){\n h->current_slice = 0;\n if (!s->first_field)\n s->current_picture_ptr= NULL;\n ff_h264_reset_sei(h);\n }\n for(;pass <= 1;pass++){\n buf_index = 0;\n context_count = 0;\n next_avc = h->is_avc ? 0 : buf_size;\n nal_index = 0;\n for(;;){\n int consumed;\n int dst_length;\n int bit_length;\n const uint8_t *ptr;\n int i, nalsize = 0;\n int err;\n if(buf_index >= next_avc) {\n if(buf_index >= buf_size) break;\n nalsize = 0;\n for(i = 0; i < h->nal_length_size; i++)\n nalsize = (nalsize << 8) | buf[buf_index++];\n if(nalsize <= 0 || nalsize > buf_size - buf_index){\n av_log(h->s.avctx, AV_LOG_ERROR, "AVC: nal size %d\\n", nalsize);\n break;\n }\n next_avc= buf_index + nalsize;\n } else {\n for(; buf_index + 3 < next_avc; buf_index++){\n if(buf[buf_index] == 0 && buf[buf_index+1] == 0 && buf[buf_index+2] == 1)\n break;\n }\n if(buf_index+3 >= buf_size) break;\n buf_index+=3;\n if(buf_index >= next_avc) continue;\n }\n hx = h->thread_context[context_count];\n ptr= ff_h264_decode_nal(hx, buf + buf_index, &dst_length, &consumed, next_avc - buf_index);\n if (ptr==NULL || dst_length < 0){\n return -1;\n }\n i= buf_index + consumed;\n if((s->workaround_bugs & FF_BUG_AUTODETECT) && i+3<next_avc &&\n buf[i]==0x00 && buf[i+1]==0x00 && buf[i+2]==0x01 && buf[i+3]==0xE0)\n s->workaround_bugs |= FF_BUG_TRUNCATED;\n if(!(s->workaround_bugs & FF_BUG_TRUNCATED)){\n while(ptr[dst_length - 1] == 0 && dst_length > 0)\n dst_length--;\n }\n bit_length= !dst_length ? 0 : (8*dst_length - ff_h264_decode_rbsp_trailing(h, ptr + dst_length - 1));\n if(s->avctx->debug&FF_DEBUG_STARTCODE){\n av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d at %d/%d length %d\\n", hx->nal_unit_type, buf_index, buf_size, dst_length);\n }\n if (h->is_avc && (nalsize != consumed) && nalsize){\n av_log(h->s.avctx, AV_LOG_DEBUG, "AVC: Consumed only %d bytes instead of %d\\n", consumed, nalsize);\n }\n buf_index += consumed;\n nal_index++;\n if(pass == 0) {\n switch (hx->nal_unit_type) {\n case NAL_SPS:\n case NAL_PPS:\n case NAL_IDR_SLICE:\n case NAL_SLICE:\n nals_needed = nal_index;\n }\n continue;\n }\n if(avctx->skip_frame >= AVDISCARD_NONREF && h->nal_ref_idc == 0)\n continue;\n again:\n err = 0;\n switch(hx->nal_unit_type){\n case NAL_IDR_SLICE:\n if (h->nal_unit_type != NAL_IDR_SLICE) {\n av_log(h->s.avctx, AV_LOG_ERROR, "Invalid mix of idr and non-idr slices");\n return -1;\n }\n idr(h);\n case NAL_SLICE:\n init_get_bits(&hx->s.gb, ptr, bit_length);\n hx->intra_gb_ptr=\n hx->inter_gb_ptr= &hx->s.gb;\n hx->s.data_partitioning = 0;\n if((err = decode_slice_header(hx, h)))\n break;\n s->current_picture_ptr->key_frame |=\n (hx->nal_unit_type == NAL_IDR_SLICE) ||\n (h->sei_recovery_frame_cnt >= 0);\n if (h->current_slice == 1) {\n if(!(s->flags2 & CODEC_FLAG2_CHUNKS)) {\n decode_postinit(h, nal_index >= nals_needed);\n }\n if (s->avctx->hwaccel && s->avctx->hwaccel->start_frame(s->avctx, NULL, 0) < 0)\n return -1;\n if(CONFIG_H264_VDPAU_DECODER && s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)\n ff_vdpau_h264_picture_start(s);\n }\n if(hx->redundant_pic_count==0\n && (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc)\n && (avctx->skip_frame < AVDISCARD_BIDIR || hx->slice_type_nos!=AV_PICTURE_TYPE_B)\n && (avctx->skip_frame < AVDISCARD_NONKEY || hx->slice_type_nos==AV_PICTURE_TYPE_I)\n && avctx->skip_frame < AVDISCARD_ALL){\n if(avctx->hwaccel) {\n if (avctx->hwaccel->decode_slice(avctx, &buf[buf_index - consumed], consumed) < 0)\n return -1;\n }else\n if(CONFIG_H264_VDPAU_DECODER && s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU){\n static const uint8_t start_code[] = {0x00, 0x00, 0x01};\n ff_vdpau_add_data_chunk(s, start_code, sizeof(start_code));\n ff_vdpau_add_data_chunk(s, &buf[buf_index - consumed], consumed );\n }else\n context_count++;\n }\n break;\n case NAL_DPA:\n init_get_bits(&hx->s.gb, ptr, bit_length);\n hx->intra_gb_ptr=\n hx->inter_gb_ptr= NULL;\n if ((err = decode_slice_header(hx, h)) < 0)\n break;\n hx->s.data_partitioning = 1;\n break;\n case NAL_DPB:\n init_get_bits(&hx->intra_gb, ptr, bit_length);\n hx->intra_gb_ptr= &hx->intra_gb;\n break;\n case NAL_DPC:\n init_get_bits(&hx->inter_gb, ptr, bit_length);\n hx->inter_gb_ptr= &hx->inter_gb;\n if(hx->redundant_pic_count==0 && hx->intra_gb_ptr && hx->s.data_partitioning\n && s->context_initialized\n && (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc)\n && (avctx->skip_frame < AVDISCARD_BIDIR || hx->slice_type_nos!=AV_PICTURE_TYPE_B)\n && (avctx->skip_frame < AVDISCARD_NONKEY || hx->slice_type_nos==AV_PICTURE_TYPE_I)\n && avctx->skip_frame < AVDISCARD_ALL)\n context_count++;\n break;\n case NAL_SEI:\n init_get_bits(&s->gb, ptr, bit_length);\n ff_h264_decode_sei(h);\n break;\n case NAL_SPS:\n init_get_bits(&s->gb, ptr, bit_length);\n ff_h264_decode_seq_parameter_set(h);\n if (s->flags& CODEC_FLAG_LOW_DELAY ||\n (h->sps.bitstream_restriction_flag && !h->sps.num_reorder_frames))\n s->low_delay=1;\n if(avctx->has_b_frames < 2)\n avctx->has_b_frames= !s->low_delay;\n if (avctx->bits_per_raw_sample != h->sps.bit_depth_luma) {\n if (h->sps.bit_depth_luma >= 8 && h->sps.bit_depth_luma <= 10) {\n avctx->bits_per_raw_sample = h->sps.bit_depth_luma;\n h->pixel_shift = h->sps.bit_depth_luma > 8;\n ff_h264dsp_init(&h->h264dsp, h->sps.bit_depth_luma);\n ff_h264_pred_init(&h->hpc, s->codec_id, h->sps.bit_depth_luma);\n dsputil_init(&s->dsp, s->avctx);\n } else {\n av_log(avctx, AV_LOG_DEBUG, "Unsupported bit depth: %d\\n", h->sps.bit_depth_luma);\n return -1;\n }\n }\n break;\n case NAL_PPS:\n init_get_bits(&s->gb, ptr, bit_length);\n ff_h264_decode_picture_parameter_set(h, bit_length);\n break;\n case NAL_AUD:\n case NAL_END_SEQUENCE:\n case NAL_END_STREAM:\n case NAL_FILLER_DATA:\n case NAL_SPS_EXT:\n case NAL_AUXILIARY_SLICE:\n break;\n default:\n av_log(avctx, AV_LOG_DEBUG, "Unknown NAL code: %d (%d bits)\\n", hx->nal_unit_type, bit_length);\n }\n if(context_count == h->max_contexts) {\n execute_decode_slices(h, context_count);\n context_count = 0;\n }\n if (err < 0)\n av_log(h->s.avctx, AV_LOG_ERROR, "decode_slice_header error\\n");\n else if(err == 1) {\n h->nal_unit_type = hx->nal_unit_type;\n h->nal_ref_idc = hx->nal_ref_idc;\n hx = h;\n goto again;\n }\n }\n }\n if(context_count)\n execute_decode_slices(h, context_count);\n return buf_index;\n}', 'static int decode_slice_header(H264Context *h, H264Context *h0){\n MpegEncContext * const s = &h->s;\n MpegEncContext * const s0 = &h0->s;\n unsigned int first_mb_in_slice;\n unsigned int pps_id;\n int num_ref_idx_active_override_flag;\n unsigned int slice_type, tmp, i, j;\n int default_ref_list_done = 0;\n int last_pic_structure;\n s->dropable= h->nal_ref_idc == 0;\n if((s->avctx->flags2 & CODEC_FLAG2_FAST) && !h->nal_ref_idc && !h->pixel_shift){\n s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab;\n s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab;\n }else{\n s->me.qpel_put= s->dsp.put_h264_qpel_pixels_tab;\n s->me.qpel_avg= s->dsp.avg_h264_qpel_pixels_tab;\n }\n first_mb_in_slice= get_ue_golomb(&s->gb);\n if(first_mb_in_slice == 0){\n if(h0->current_slice && FIELD_PICTURE){\n field_end(h, 1);\n }\n h0->current_slice = 0;\n if (!s0->first_field)\n s->current_picture_ptr= NULL;\n }\n slice_type= get_ue_golomb_31(&s->gb);\n if(slice_type > 9){\n av_log(h->s.avctx, AV_LOG_ERROR, "slice type too large (%d) at %d %d\\n", h->slice_type, s->mb_x, s->mb_y);\n return -1;\n }\n if(slice_type > 4){\n slice_type -= 5;\n h->slice_type_fixed=1;\n }else\n h->slice_type_fixed=0;\n slice_type= golomb_to_pict_type[ slice_type ];\n if (slice_type == AV_PICTURE_TYPE_I\n || (h0->current_slice != 0 && slice_type == h0->last_slice_type) ) {\n default_ref_list_done = 1;\n }\n h->slice_type= slice_type;\n h->slice_type_nos= slice_type & 3;\n s->pict_type= h->slice_type;\n pps_id= get_ue_golomb(&s->gb);\n if(pps_id>=MAX_PPS_COUNT){\n av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\\n");\n return -1;\n }\n if(!h0->pps_buffers[pps_id]) {\n av_log(h->s.avctx, AV_LOG_ERROR, "non-existing PPS %u referenced\\n", pps_id);\n return -1;\n }\n h->pps= *h0->pps_buffers[pps_id];\n if(!h0->sps_buffers[h->pps.sps_id]) {\n av_log(h->s.avctx, AV_LOG_ERROR, "non-existing SPS %u referenced\\n", h->pps.sps_id);\n return -1;\n }\n h->sps = *h0->sps_buffers[h->pps.sps_id];\n s->avctx->profile = ff_h264_get_profile(&h->sps);\n s->avctx->level = h->sps.level_idc;\n s->avctx->refs = h->sps.ref_frame_count;\n if(h == h0 && h->dequant_coeff_pps != pps_id){\n h->dequant_coeff_pps = pps_id;\n init_dequant_tables(h);\n }\n s->mb_width= h->sps.mb_width;\n s->mb_height= h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag);\n h->b_stride= s->mb_width*4;\n s->width = 16*s->mb_width - (2>>CHROMA444)*FFMIN(h->sps.crop_right, (8<<CHROMA444)-1);\n if(h->sps.frame_mbs_only_flag)\n s->height= 16*s->mb_height - (2>>CHROMA444)*FFMIN(h->sps.crop_bottom, (8<<CHROMA444)-1);\n else\n s->height= 16*s->mb_height - (4>>CHROMA444)*FFMIN(h->sps.crop_bottom, (8<<CHROMA444)-1);\n if (s->context_initialized\n && ( s->width != s->avctx->width || s->height != s->avctx->height\n || av_cmp_q(h->sps.sar, s->avctx->sample_aspect_ratio))) {\n if(h != h0) {\n av_log_missing_feature(s->avctx, "Width/height changing with threads is", 0);\n return -1;\n }\n free_tables(h, 0);\n flush_dpb(s->avctx);\n MPV_common_end(s);\n }\n if (!s->context_initialized) {\n if (h != h0) {\n av_log(h->s.avctx, AV_LOG_ERROR, "Cannot (re-)initialize context during parallel decoding.\\n");\n return -1;\n }\n avcodec_set_dimensions(s->avctx, s->width, s->height);\n s->avctx->sample_aspect_ratio= h->sps.sar;\n av_assert0(s->avctx->sample_aspect_ratio.den);\n h->s.avctx->coded_width = 16*s->mb_width;\n h->s.avctx->coded_height = 16*s->mb_height;\n if(h->sps.video_signal_type_present_flag){\n s->avctx->color_range = h->sps.full_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;\n if(h->sps.colour_description_present_flag){\n s->avctx->color_primaries = h->sps.color_primaries;\n s->avctx->color_trc = h->sps.color_trc;\n s->avctx->colorspace = h->sps.colorspace;\n }\n }\n if(h->sps.timing_info_present_flag){\n int64_t den= h->sps.time_scale;\n if(h->x264_build < 44U)\n den *= 2;\n av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den,\n h->sps.num_units_in_tick, den, 1<<30);\n }\n switch (h->sps.bit_depth_luma) {\n case 9 :\n s->avctx->pix_fmt = CHROMA444 ? PIX_FMT_YUV444P9 : PIX_FMT_YUV420P9;\n break;\n case 10 :\n s->avctx->pix_fmt = CHROMA444 ? PIX_FMT_YUV444P10 : PIX_FMT_YUV420P10;\n break;\n default:\n if (CHROMA444){\n s->avctx->pix_fmt = s->avctx->color_range == AVCOL_RANGE_JPEG ? PIX_FMT_YUVJ444P : PIX_FMT_YUV444P;\n }else{\n s->avctx->pix_fmt = s->avctx->get_format(s->avctx,\n s->avctx->codec->pix_fmts ?\n s->avctx->codec->pix_fmts :\n s->avctx->color_range == AVCOL_RANGE_JPEG ?\n hwaccel_pixfmt_list_h264_jpeg_420 :\n ff_hwaccel_pixfmt_list_420);\n }\n }\n s->avctx->hwaccel = ff_find_hwaccel(s->avctx->codec->id, s->avctx->pix_fmt);\n if (MPV_common_init(s) < 0) {\n av_log(h->s.avctx, AV_LOG_ERROR, "MPV_common_init() failed.\\n");\n return -1;\n }\n s->first_field = 0;\n h->prev_interlaced_frame = 1;\n init_scan_tables(h);\n ff_h264_alloc_tables(h);\n if (!HAVE_THREADS || !(s->avctx->active_thread_type&FF_THREAD_SLICE)) {\n if (context_init(h) < 0) {\n av_log(h->s.avctx, AV_LOG_ERROR, "context_init() failed.\\n");\n return -1;\n }\n } else {\n for(i = 1; i < s->avctx->thread_count; i++) {\n H264Context *c;\n c = h->thread_context[i] = av_malloc(sizeof(H264Context));\n memcpy(c, h->s.thread_context[i], sizeof(MpegEncContext));\n memset(&c->s + 1, 0, sizeof(H264Context) - sizeof(MpegEncContext));\n c->h264dsp = h->h264dsp;\n c->sps = h->sps;\n c->pps = h->pps;\n c->pixel_shift = h->pixel_shift;\n init_scan_tables(c);\n clone_tables(c, h, i);\n }\n for(i = 0; i < s->avctx->thread_count; i++)\n if (context_init(h->thread_context[i]) < 0) {\n av_log(h->s.avctx, AV_LOG_ERROR, "context_init() failed.\\n");\n return -1;\n }\n }\n }\n h->frame_num= get_bits(&s->gb, h->sps.log2_max_frame_num);\n h->mb_mbaff = 0;\n h->mb_aff_frame = 0;\n last_pic_structure = s0->picture_structure;\n if(h->sps.frame_mbs_only_flag){\n s->picture_structure= PICT_FRAME;\n }else{\n if(get_bits1(&s->gb)) {\n s->picture_structure= PICT_TOP_FIELD + get_bits1(&s->gb);\n } else {\n s->picture_structure= PICT_FRAME;\n h->mb_aff_frame = h->sps.mb_aff;\n }\n }\n h->mb_field_decoding_flag= s->picture_structure != PICT_FRAME;\n if(h0->current_slice == 0){\n if(h->frame_num != h->prev_frame_num) {\n int unwrap_prev_frame_num = h->prev_frame_num, max_frame_num = 1<<h->sps.log2_max_frame_num;\n if (unwrap_prev_frame_num > h->frame_num) unwrap_prev_frame_num -= max_frame_num;\n if ((h->frame_num - unwrap_prev_frame_num) > h->sps.ref_frame_count) {\n unwrap_prev_frame_num = (h->frame_num - h->sps.ref_frame_count) - 1;\n if (unwrap_prev_frame_num < 0)\n unwrap_prev_frame_num += max_frame_num;\n h->prev_frame_num = unwrap_prev_frame_num;\n }\n }\n while(h->frame_num != h->prev_frame_num &&\n h->frame_num != (h->prev_frame_num+1)%(1<<h->sps.log2_max_frame_num)){\n Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL;\n av_log(h->s.avctx, AV_LOG_DEBUG, "Frame num gap %d %d\\n", h->frame_num, h->prev_frame_num);\n if (ff_h264_frame_start(h) < 0)\n return -1;\n h->prev_frame_num++;\n h->prev_frame_num %= 1<<h->sps.log2_max_frame_num;\n s->current_picture_ptr->frame_num= h->prev_frame_num;\n ff_thread_report_progress((AVFrame*)s->current_picture_ptr, INT_MAX, 0);\n ff_thread_report_progress((AVFrame*)s->current_picture_ptr, INT_MAX, 1);\n ff_generate_sliding_window_mmcos(h);\n ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);\n if (h->short_ref_count) {\n if (prev) {\n av_image_copy(h->short_ref[0]->data, h->short_ref[0]->linesize,\n (const uint8_t**)prev->data, prev->linesize,\n s->avctx->pix_fmt, s->mb_width*16, s->mb_height*16);\n h->short_ref[0]->poc = prev->poc+2;\n }\n h->short_ref[0]->frame_num = h->prev_frame_num;\n }\n }\n if (s0->first_field) {\n assert(s0->current_picture_ptr);\n assert(s0->current_picture_ptr->data[0]);\n assert(s0->current_picture_ptr->reference != DELAYED_PIC_REF);\n if (!FIELD_PICTURE || s->picture_structure == last_pic_structure) {\n s0->current_picture_ptr = NULL;\n s0->first_field = FIELD_PICTURE;\n } else {\n if (h->nal_ref_idc &&\n s0->current_picture_ptr->reference &&\n s0->current_picture_ptr->frame_num != h->frame_num) {\n s0->first_field = 1;\n s0->current_picture_ptr = NULL;\n } else {\n s0->first_field = 0;\n }\n }\n } else {\n assert(!s0->current_picture_ptr);\n s0->first_field = FIELD_PICTURE;\n }\n if(!FIELD_PICTURE || s0->first_field) {\n if (ff_h264_frame_start(h) < 0) {\n s0->first_field = 0;\n return -1;\n }\n } else {\n ff_release_unused_pictures(s, 0);\n }\n }\n if(h != h0)\n clone_slice(h, h0);\n s->current_picture_ptr->frame_num= h->frame_num;\n assert(s->mb_num == s->mb_width * s->mb_height);\n if(first_mb_in_slice << FIELD_OR_MBAFF_PICTURE >= s->mb_num ||\n first_mb_in_slice >= s->mb_num){\n av_log(h->s.avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\\n");\n return -1;\n }\n s->resync_mb_x = s->mb_x = first_mb_in_slice % s->mb_width;\n s->resync_mb_y = s->mb_y = (first_mb_in_slice / s->mb_width) << FIELD_OR_MBAFF_PICTURE;\n if (s->picture_structure == PICT_BOTTOM_FIELD)\n s->resync_mb_y = s->mb_y = s->mb_y + 1;\n assert(s->mb_y < s->mb_height);\n if(s->picture_structure==PICT_FRAME){\n h->curr_pic_num= h->frame_num;\n h->max_pic_num= 1<< h->sps.log2_max_frame_num;\n }else{\n h->curr_pic_num= 2*h->frame_num + 1;\n h->max_pic_num= 1<<(h->sps.log2_max_frame_num + 1);\n }\n if(h->nal_unit_type == NAL_IDR_SLICE){\n get_ue_golomb(&s->gb);\n }\n if(h->sps.poc_type==0){\n h->poc_lsb= get_bits(&s->gb, h->sps.log2_max_poc_lsb);\n if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME){\n h->delta_poc_bottom= get_se_golomb(&s->gb);\n }\n }\n if(h->sps.poc_type==1 && !h->sps.delta_pic_order_always_zero_flag){\n h->delta_poc[0]= get_se_golomb(&s->gb);\n if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME)\n h->delta_poc[1]= get_se_golomb(&s->gb);\n }\n init_poc(h);\n if(h->pps.redundant_pic_cnt_present){\n h->redundant_pic_count= get_ue_golomb(&s->gb);\n }\n h->ref_count[0]= h->pps.ref_count[0];\n h->ref_count[1]= h->pps.ref_count[1];\n if(h->slice_type_nos != AV_PICTURE_TYPE_I){\n if(h->slice_type_nos == AV_PICTURE_TYPE_B){\n h->direct_spatial_mv_pred= get_bits1(&s->gb);\n }\n num_ref_idx_active_override_flag= get_bits1(&s->gb);\n if(num_ref_idx_active_override_flag){\n h->ref_count[0]= get_ue_golomb(&s->gb) + 1;\n if(h->slice_type_nos==AV_PICTURE_TYPE_B)\n h->ref_count[1]= get_ue_golomb(&s->gb) + 1;\n if(h->ref_count[0]-1 > 32-1 || h->ref_count[1]-1 > 32-1){\n av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\\n");\n h->ref_count[0]= h->ref_count[1]= 1;\n return -1;\n }\n }\n if(h->slice_type_nos == AV_PICTURE_TYPE_B)\n h->list_count= 2;\n else\n h->list_count= 1;\n }else\n h->list_count= 0;\n if(!default_ref_list_done){\n ff_h264_fill_default_ref_list(h);\n }\n if(h->slice_type_nos!=AV_PICTURE_TYPE_I && ff_h264_decode_ref_pic_list_reordering(h) < 0)\n return -1;\n if(h->slice_type_nos!=AV_PICTURE_TYPE_I){\n s->last_picture_ptr= &h->ref_list[0][0];\n ff_copy_picture(&s->last_picture, s->last_picture_ptr);\n }\n if(h->slice_type_nos==AV_PICTURE_TYPE_B){\n s->next_picture_ptr= &h->ref_list[1][0];\n ff_copy_picture(&s->next_picture, s->next_picture_ptr);\n }\n if( (h->pps.weighted_pred && h->slice_type_nos == AV_PICTURE_TYPE_P )\n || (h->pps.weighted_bipred_idc==1 && h->slice_type_nos== AV_PICTURE_TYPE_B ) )\n pred_weight_table(h);\n else if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== AV_PICTURE_TYPE_B){\n implicit_weight_table(h, -1);\n }else {\n h->use_weight = 0;\n for (i = 0; i < 2; i++) {\n h->luma_weight_flag[i] = 0;\n h->chroma_weight_flag[i] = 0;\n }\n }\n if(h->nal_ref_idc)\n ff_h264_decode_ref_pic_marking(h0, &s->gb);\n if(FRAME_MBAFF){\n ff_h264_fill_mbaff_ref_list(h);\n if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== AV_PICTURE_TYPE_B){\n implicit_weight_table(h, 0);\n implicit_weight_table(h, 1);\n }\n }\n if(h->slice_type_nos==AV_PICTURE_TYPE_B && !h->direct_spatial_mv_pred)\n ff_h264_direct_dist_scale_factor(h);\n ff_h264_direct_ref_list_init(h);\n if( h->slice_type_nos != AV_PICTURE_TYPE_I && h->pps.cabac ){\n tmp = get_ue_golomb_31(&s->gb);\n if(tmp > 2){\n av_log(s->avctx, AV_LOG_ERROR, "cabac_init_idc overflow\\n");\n return -1;\n }\n h->cabac_init_idc= tmp;\n }\n h->last_qscale_diff = 0;\n tmp = h->pps.init_qp + get_se_golomb(&s->gb);\n if(tmp>51+6*(h->sps.bit_depth_luma-8)){\n av_log(s->avctx, AV_LOG_ERROR, "QP %u out of range\\n", tmp);\n return -1;\n }\n s->qscale= tmp;\n h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale);\n h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale);\n if(h->slice_type == AV_PICTURE_TYPE_SP){\n get_bits1(&s->gb);\n }\n if(h->slice_type==AV_PICTURE_TYPE_SP || h->slice_type == AV_PICTURE_TYPE_SI){\n get_se_golomb(&s->gb);\n }\n h->deblocking_filter = 1;\n h->slice_alpha_c0_offset = 52;\n h->slice_beta_offset = 52;\n if( h->pps.deblocking_filter_parameters_present ) {\n tmp= get_ue_golomb_31(&s->gb);\n if(tmp > 2){\n av_log(s->avctx, AV_LOG_ERROR, "deblocking_filter_idc %u out of range\\n", tmp);\n return -1;\n }\n h->deblocking_filter= tmp;\n if(h->deblocking_filter < 2)\n h->deblocking_filter^= 1;\n if( h->deblocking_filter ) {\n h->slice_alpha_c0_offset += get_se_golomb(&s->gb) << 1;\n h->slice_beta_offset += get_se_golomb(&s->gb) << 1;\n if( h->slice_alpha_c0_offset > 104U\n || h->slice_beta_offset > 104U){\n av_log(s->avctx, AV_LOG_ERROR, "deblocking filter parameters %d %d out of range\\n", h->slice_alpha_c0_offset, h->slice_beta_offset);\n return -1;\n }\n }\n }\n if( s->avctx->skip_loop_filter >= AVDISCARD_ALL\n ||(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY && h->slice_type_nos != AV_PICTURE_TYPE_I)\n ||(s->avctx->skip_loop_filter >= AVDISCARD_BIDIR && h->slice_type_nos == AV_PICTURE_TYPE_B)\n ||(s->avctx->skip_loop_filter >= AVDISCARD_NONREF && h->nal_ref_idc == 0))\n h->deblocking_filter= 0;\n if(h->deblocking_filter == 1 && h0->max_contexts > 1) {\n if(s->avctx->flags2 & CODEC_FLAG2_FAST) {\n h->deblocking_filter = 2;\n } else {\n h0->max_contexts = 1;\n if(!h0->single_decode_warning) {\n av_log(s->avctx, AV_LOG_INFO, "Cannot parallelize deblocking type 1, decoding such frames in sequential order\\n");\n h0->single_decode_warning = 1;\n }\n if (h != h0) {\n av_log(h->s.avctx, AV_LOG_ERROR, "Deblocking switched inside frame.\\n");\n return 1;\n }\n }\n }\n h->qp_thresh = 15 + 52 - FFMIN(h->slice_alpha_c0_offset, h->slice_beta_offset)\n - FFMAX3(0, h->pps.chroma_qp_index_offset[0], h->pps.chroma_qp_index_offset[1])\n + 6 * (h->sps.bit_depth_luma - 8);\n#if 0\n if( h->pps.num_slice_groups > 1 && h->pps.mb_slice_group_map_type >= 3 && h->pps.mb_slice_group_map_type <= 5)\n slice_group_change_cycle= get_bits(&s->gb, ?);\n#endif\n h0->last_slice_type = slice_type;\n h->slice_num = ++h0->current_slice;\n if(h->slice_num >= MAX_SLICES){\n av_log(s->avctx, AV_LOG_ERROR, "Too many slices, increase MAX_SLICES and recompile\\n");\n }\n for(j=0; j<2; j++){\n int id_list[16];\n int *ref2frm= h->ref2frm[h->slice_num&(MAX_SLICES-1)][j];\n for(i=0; i<16; i++){\n id_list[i]= 60;\n if(h->ref_list[j][i].data[0]){\n int k;\n uint8_t *base= h->ref_list[j][i].base[0];\n for(k=0; k<h->short_ref_count; k++)\n if(h->short_ref[k]->base[0] == base){\n id_list[i]= k;\n break;\n }\n for(k=0; k<h->long_ref_count; k++)\n if(h->long_ref[k] && h->long_ref[k]->base[0] == base){\n id_list[i]= h->short_ref_count + k;\n break;\n }\n }\n }\n ref2frm[0]=\n ref2frm[1]= -1;\n for(i=0; i<16; i++)\n ref2frm[i+2]= 4*id_list[i]\n +(h->ref_list[j][i].reference&3);\n ref2frm[18+0]=\n ref2frm[18+1]= -1;\n for(i=16; i<48; i++)\n ref2frm[i+4]= 4*id_list[(i-16)>>1]\n +(h->ref_list[j][i].reference&3);\n }\n h->emu_edge_width= (s->flags&CODEC_FLAG_EMU_EDGE || (!h->sps.frame_mbs_only_flag && s->avctx->active_thread_type)) ? 0 : 16;\n h->emu_edge_height= (FRAME_MBAFF || FIELD_PICTURE) ? 0 : h->emu_edge_width;\n if(s->avctx->debug&FF_DEBUG_PICT_INFO){\n av_log(h->s.avctx, AV_LOG_DEBUG, "slice:%d %s mb:%d %c%s%s pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\\n",\n h->slice_num,\n (s->picture_structure==PICT_FRAME ? "F" : s->picture_structure==PICT_TOP_FIELD ? "T" : "B"),\n first_mb_in_slice,\n av_get_picture_type_char(h->slice_type), h->slice_type_fixed ? " fix" : "", h->nal_unit_type == NAL_IDR_SLICE ? " IDR" : "",\n pps_id, h->frame_num,\n s->current_picture_ptr->field_poc[0], s->current_picture_ptr->field_poc[1],\n h->ref_count[0], h->ref_count[1],\n s->qscale,\n h->deblocking_filter, h->slice_alpha_c0_offset/2-26, h->slice_beta_offset/2-26,\n h->use_weight,\n h->use_weight==1 && h->use_weight_chroma ? "c" : "",\n h->slice_type == AV_PICTURE_TYPE_B ? (h->direct_spatial_mv_pred ? "SPAT" : "TEMP") : ""\n );\n }\n return 0;\n}', 'static void field_end(H264Context *h, int in_setup){\n MpegEncContext * const s = &h->s;\n AVCodecContext * const avctx= s->avctx;\n s->mb_y= 0;\n if (!in_setup && !s->dropable)\n ff_thread_report_progress((AVFrame*)s->current_picture_ptr, (16*s->mb_height >> FIELD_PICTURE) - 1,\n s->picture_structure==PICT_BOTTOM_FIELD);\n if (CONFIG_H264_VDPAU_DECODER && s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)\n ff_vdpau_h264_set_reference_frames(s);\n if(in_setup || !(avctx->active_thread_type&FF_THREAD_FRAME)){\n if(!s->dropable) {\n ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);\n h->prev_poc_msb= h->poc_msb;\n h->prev_poc_lsb= h->poc_lsb;\n }\n h->prev_frame_num_offset= h->frame_num_offset;\n h->prev_frame_num= h->frame_num;\n h->outputed_poc = h->next_outputed_poc;\n }\n if (avctx->hwaccel) {\n if (avctx->hwaccel->end_frame(avctx) < 0)\n av_log(avctx, AV_LOG_ERROR, "hardware accelerator failed to decode picture\\n");\n }\n if (CONFIG_H264_VDPAU_DECODER && s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)\n ff_vdpau_h264_picture_complete(s);\n if (!FIELD_PICTURE)\n ff_er_frame_end(s);\n MPV_frame_end(s);\n h->current_slice=0;\n}', 'void ff_er_frame_end(MpegEncContext *s){\n int i, mb_x, mb_y, error, error_type, dc_error, mv_error, ac_error;\n int distance;\n int threshold_part[4]= {100,100,100};\n int threshold= 50;\n int is_intra_likely;\n int size = s->b8_stride * 2 * s->mb_height;\n Picture *pic= s->current_picture_ptr;\n if(!s->error_recognition || s->error_count==0 || s->avctx->lowres ||\n s->avctx->hwaccel ||\n s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU ||\n s->picture_structure != PICT_FRAME ||\n s->error_count==3*s->mb_width*(s->avctx->skip_top + s->avctx->skip_bottom)) return;\n if(s->current_picture.motion_val[0] == NULL){\n av_log(s->avctx, AV_LOG_ERROR, "Warning MVs not available\\n");\n for(i=0; i<2; i++){\n pic->ref_index[i]= av_mallocz(s->mb_stride * s->mb_height * 4 * sizeof(uint8_t));\n pic->motion_val_base[i]= av_mallocz((size+4) * 2 * sizeof(uint16_t));\n pic->motion_val[i]= pic->motion_val_base[i]+4;\n }\n pic->motion_subsample_log2= 3;\n s->current_picture= *s->current_picture_ptr;\n }\n if(s->avctx->debug&FF_DEBUG_ER){\n for(mb_y=0; mb_y<s->mb_height; mb_y++){\n for(mb_x=0; mb_x<s->mb_width; mb_x++){\n int status= s->error_status_table[mb_x + mb_y*s->mb_stride];\n av_log(s->avctx, AV_LOG_DEBUG, "%2X ", status);\n }\n av_log(s->avctx, AV_LOG_DEBUG, "\\n");\n }\n }\n for(error_type=1; error_type<=3; error_type++){\n int end_ok=0;\n for(i=s->mb_num-1; i>=0; i--){\n const int mb_xy= s->mb_index2xy[i];\n int error= s->error_status_table[mb_xy];\n if(error&(1<<error_type))\n end_ok=1;\n if(error&(8<<error_type))\n end_ok=1;\n if(!end_ok)\n s->error_status_table[mb_xy]|= 1<<error_type;\n if(error&VP_START)\n end_ok=0;\n }\n }\n if(s->partitioned_frame){\n int end_ok=0;\n for(i=s->mb_num-1; i>=0; i--){\n const int mb_xy= s->mb_index2xy[i];\n int error= s->error_status_table[mb_xy];\n if(error&AC_END)\n end_ok=0;\n if((error&MV_END) || (error&DC_END) || (error&AC_ERROR))\n end_ok=1;\n if(!end_ok)\n s->error_status_table[mb_xy]|= AC_ERROR;\n if(error&VP_START)\n end_ok=0;\n }\n }\n if(s->error_recognition>=4){\n int end_ok=1;\n for(i=s->mb_num-2; i>=s->mb_width+100; i--){\n const int mb_xy= s->mb_index2xy[i];\n int error1= s->error_status_table[mb_xy ];\n int error2= s->error_status_table[s->mb_index2xy[i+1]];\n if(error1&VP_START)\n end_ok=1;\n if( error2==(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END)\n && error1!=(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END)\n && ((error1&AC_END) || (error1&DC_END) || (error1&MV_END))){\n end_ok=0;\n }\n if(!end_ok)\n s->error_status_table[mb_xy]|= DC_ERROR|AC_ERROR|MV_ERROR;\n }\n }\n distance=9999999;\n for(error_type=1; error_type<=3; error_type++){\n for(i=s->mb_num-1; i>=0; i--){\n const int mb_xy= s->mb_index2xy[i];\n int error= s->error_status_table[mb_xy];\n if(!s->mbskip_table[mb_xy])\n distance++;\n if(error&(1<<error_type))\n distance= 0;\n if(s->partitioned_frame){\n if(distance < threshold_part[error_type-1])\n s->error_status_table[mb_xy]|= 1<<error_type;\n }else{\n if(distance < threshold)\n s->error_status_table[mb_xy]|= 1<<error_type;\n }\n if(error&VP_START)\n distance= 9999999;\n }\n }\n error=0;\n for(i=0; i<s->mb_num; i++){\n const int mb_xy= s->mb_index2xy[i];\n int old_error= s->error_status_table[mb_xy];\n if(old_error&VP_START)\n error= old_error& (DC_ERROR|AC_ERROR|MV_ERROR);\n else{\n error|= old_error& (DC_ERROR|AC_ERROR|MV_ERROR);\n s->error_status_table[mb_xy]|= error;\n }\n }\n if(!s->partitioned_frame){\n for(i=0; i<s->mb_num; i++){\n const int mb_xy= s->mb_index2xy[i];\n error= s->error_status_table[mb_xy];\n if(error&(AC_ERROR|DC_ERROR|MV_ERROR))\n error|= AC_ERROR|DC_ERROR|MV_ERROR;\n s->error_status_table[mb_xy]= error;\n }\n }\n dc_error= ac_error= mv_error=0;\n for(i=0; i<s->mb_num; i++){\n const int mb_xy= s->mb_index2xy[i];\n error= s->error_status_table[mb_xy];\n if(error&DC_ERROR) dc_error ++;\n if(error&AC_ERROR) ac_error ++;\n if(error&MV_ERROR) mv_error ++;\n }\n av_log(s->avctx, AV_LOG_INFO, "concealing %d DC, %d AC, %d MV errors\\n", dc_error, ac_error, mv_error);\n is_intra_likely= is_intra_more_likely(s);\n for(i=0; i<s->mb_num; i++){\n const int mb_xy= s->mb_index2xy[i];\n error= s->error_status_table[mb_xy];\n if(!((error&DC_ERROR) && (error&MV_ERROR)))\n continue;\n if(is_intra_likely)\n s->current_picture.mb_type[mb_xy]= MB_TYPE_INTRA4x4;\n else\n s->current_picture.mb_type[mb_xy]= MB_TYPE_16x16 | MB_TYPE_L0;\n }\n if (!s->last_picture.data[0] && !s->next_picture.data[0])\n for(i=0; i<s->mb_num; i++){\n const int mb_xy= s->mb_index2xy[i];\n if(!IS_INTRA(s->current_picture.mb_type[mb_xy]))\n s->current_picture.mb_type[mb_xy]= MB_TYPE_INTRA4x4;\n }\n for(mb_y=0; mb_y<s->mb_height; mb_y++){\n for(mb_x=0; mb_x<s->mb_width; mb_x++){\n const int mb_xy= mb_x + mb_y * s->mb_stride;\n const int mb_type= s->current_picture.mb_type[mb_xy];\n int dir = !s->last_picture.data[0];\n error= s->error_status_table[mb_xy];\n if(IS_INTRA(mb_type)) continue;\n if(error&MV_ERROR) continue;\n if(!(error&AC_ERROR)) continue;\n s->mv_dir = dir ? MV_DIR_BACKWARD : MV_DIR_FORWARD;\n s->mb_intra=0;\n s->mb_skipped=0;\n if(IS_8X8(mb_type)){\n int mb_index= mb_x*2 + mb_y*2*s->b8_stride;\n int j;\n s->mv_type = MV_TYPE_8X8;\n for(j=0; j<4; j++){\n s->mv[0][j][0] = s->current_picture.motion_val[dir][ mb_index + (j&1) + (j>>1)*s->b8_stride ][0];\n s->mv[0][j][1] = s->current_picture.motion_val[dir][ mb_index + (j&1) + (j>>1)*s->b8_stride ][1];\n }\n }else{\n s->mv_type = MV_TYPE_16X16;\n s->mv[0][0][0] = s->current_picture.motion_val[dir][ mb_x*2 + mb_y*2*s->b8_stride ][0];\n s->mv[0][0][1] = s->current_picture.motion_val[dir][ mb_x*2 + mb_y*2*s->b8_stride ][1];\n }\n s->dsp.clear_blocks(s->block[0]);\n s->mb_x= mb_x;\n s->mb_y= mb_y;\n decode_mb(s, 0 );\n }\n }\n if(s->pict_type==AV_PICTURE_TYPE_B){\n for(mb_y=0; mb_y<s->mb_height; mb_y++){\n for(mb_x=0; mb_x<s->mb_width; mb_x++){\n int xy= mb_x*2 + mb_y*2*s->b8_stride;\n const int mb_xy= mb_x + mb_y * s->mb_stride;\n const int mb_type= s->current_picture.mb_type[mb_xy];\n error= s->error_status_table[mb_xy];\n if(IS_INTRA(mb_type)) continue;\n if(!(error&MV_ERROR)) continue;\n if(!(error&AC_ERROR)) continue;\n s->mv_dir = MV_DIR_FORWARD|MV_DIR_BACKWARD;\n if(!s->last_picture.data[0]) s->mv_dir &= ~MV_DIR_FORWARD;\n if(!s->next_picture.data[0]) s->mv_dir &= ~MV_DIR_BACKWARD;\n s->mb_intra=0;\n s->mv_type = MV_TYPE_16X16;\n s->mb_skipped=0;\n if(s->pp_time){\n int time_pp= s->pp_time;\n int time_pb= s->pb_time;\n if (s->avctx->codec_id == CODEC_ID_H264) {\n } else {\n ff_thread_await_progress((AVFrame *) s->next_picture_ptr,\n mb_y, 0);\n }\n s->mv[0][0][0] = s->next_picture.motion_val[0][xy][0]*time_pb/time_pp;\n s->mv[0][0][1] = s->next_picture.motion_val[0][xy][1]*time_pb/time_pp;\n s->mv[1][0][0] = s->next_picture.motion_val[0][xy][0]*(time_pb - time_pp)/time_pp;\n s->mv[1][0][1] = s->next_picture.motion_val[0][xy][1]*(time_pb - time_pp)/time_pp;\n }else{\n s->mv[0][0][0]= 0;\n s->mv[0][0][1]= 0;\n s->mv[1][0][0]= 0;\n s->mv[1][0][1]= 0;\n }\n s->dsp.clear_blocks(s->block[0]);\n s->mb_x= mb_x;\n s->mb_y= mb_y;\n decode_mb(s, 0);\n }\n }\n }else\n guess_mv(s);\n if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration)\n goto ec_clean;\n for(mb_y=0; mb_y<s->mb_height; mb_y++){\n for(mb_x=0; mb_x<s->mb_width; mb_x++){\n int dc, dcu, dcv, y, n;\n int16_t *dc_ptr;\n uint8_t *dest_y, *dest_cb, *dest_cr;\n const int mb_xy= mb_x + mb_y * s->mb_stride;\n const int mb_type= s->current_picture.mb_type[mb_xy];\n error= s->error_status_table[mb_xy];\n if(IS_INTRA(mb_type) && s->partitioned_frame) continue;\n dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;\n dest_cb= s->current_picture.data[1] + mb_x*8 + mb_y*8 *s->uvlinesize;\n dest_cr= s->current_picture.data[2] + mb_x*8 + mb_y*8 *s->uvlinesize;\n dc_ptr= &s->dc_val[0][mb_x*2 + mb_y*2*s->b8_stride];\n for(n=0; n<4; n++){\n dc=0;\n for(y=0; y<8; y++){\n int x;\n for(x=0; x<8; x++){\n dc+= dest_y[x + (n&1)*8 + (y + (n>>1)*8)*s->linesize];\n }\n }\n dc_ptr[(n&1) + (n>>1)*s->b8_stride]= (dc+4)>>3;\n }\n dcu=dcv=0;\n for(y=0; y<8; y++){\n int x;\n for(x=0; x<8; x++){\n dcu+=dest_cb[x + y*(s->uvlinesize)];\n dcv+=dest_cr[x + y*(s->uvlinesize)];\n }\n }\n s->dc_val[1][mb_x + mb_y*s->mb_stride]= (dcu+4)>>3;\n s->dc_val[2][mb_x + mb_y*s->mb_stride]= (dcv+4)>>3;\n }\n }\n guess_dc(s, s->dc_val[0], s->mb_width*2, s->mb_height*2, s->b8_stride, 1);\n guess_dc(s, s->dc_val[1], s->mb_width , s->mb_height , s->mb_stride, 0);\n guess_dc(s, s->dc_val[2], s->mb_width , s->mb_height , s->mb_stride, 0);\n filter181(s->dc_val[0], s->mb_width*2, s->mb_height*2, s->b8_stride);\n for(mb_y=0; mb_y<s->mb_height; mb_y++){\n for(mb_x=0; mb_x<s->mb_width; mb_x++){\n uint8_t *dest_y, *dest_cb, *dest_cr;\n const int mb_xy= mb_x + mb_y * s->mb_stride;\n const int mb_type= s->current_picture.mb_type[mb_xy];\n error= s->error_status_table[mb_xy];\n if(IS_INTER(mb_type)) continue;\n if(!(error&AC_ERROR)) continue;\n dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;\n dest_cb= s->current_picture.data[1] + mb_x*8 + mb_y*8 *s->uvlinesize;\n dest_cr= s->current_picture.data[2] + mb_x*8 + mb_y*8 *s->uvlinesize;\n put_dc(s, dest_y, dest_cb, dest_cr, mb_x, mb_y);\n }\n }\n if(s->avctx->error_concealment&FF_EC_DEBLOCK){\n h_block_filter(s, s->current_picture.data[0], s->mb_width*2, s->mb_height*2, s->linesize , 1);\n h_block_filter(s, s->current_picture.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0);\n h_block_filter(s, s->current_picture.data[2], s->mb_width , s->mb_height , s->uvlinesize, 0);\n v_block_filter(s, s->current_picture.data[0], s->mb_width*2, s->mb_height*2, s->linesize , 1);\n v_block_filter(s, s->current_picture.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0);\n v_block_filter(s, s->current_picture.data[2], s->mb_width , s->mb_height , s->uvlinesize, 0);\n }\nec_clean:\n for(i=0; i<s->mb_num; i++){\n const int mb_xy= s->mb_index2xy[i];\n int error= s->error_status_table[mb_xy];\n if(s->pict_type!=AV_PICTURE_TYPE_B && (error&(DC_ERROR|MV_ERROR|AC_ERROR))){\n s->mbskip_table[mb_xy]=0;\n }\n s->mbintra_table[mb_xy]=1;\n }\n}', 'static void decode_mb(MpegEncContext *s, int ref){\n s->dest[0] = s->current_picture.data[0] + (s->mb_y * 16* s->linesize ) + s->mb_x * 16;\n s->dest[1] = s->current_picture.data[1] + (s->mb_y * (16>>s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16>>s->chroma_x_shift);\n s->dest[2] = s->current_picture.data[2] + (s->mb_y * (16>>s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16>>s->chroma_x_shift);\n if(CONFIG_H264_DECODER && s->codec_id == CODEC_ID_H264){\n H264Context *h= (void*)s;\n h->mb_xy= s->mb_x + s->mb_y*s->mb_stride;\n memset(h->non_zero_count_cache, 0, sizeof(h->non_zero_count_cache));\n assert(ref>=0);\n if(ref >= h->ref_count[0])\n ref=0;\n fill_rectangle(&s->current_picture.ref_index[0][4*h->mb_xy], 2, 2, 2, ref, 1);\n fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);\n fill_rectangle(h->mv_cache[0][ scan8[0] ], 4, 4, 8, pack16to32(s->mv[0][0][0],s->mv[0][0][1]), 4);\n assert(!FRAME_MBAFF);\n ff_h264_hl_decode_mb(h);\n }else{\n assert(ref==0);\n MPV_decode_mb(s, s->block);\n }\n}', 'void ff_h264_hl_decode_mb(H264Context *h){\n MpegEncContext * const s = &h->s;\n const int mb_xy= h->mb_xy;\n const int mb_type= s->current_picture.mb_type[mb_xy];\n int is_complex = CONFIG_SMALL || h->is_complex || IS_INTRA_PCM(mb_type) || s->qscale == 0;\n if (CHROMA444) {\n if(is_complex || h->pixel_shift)\n hl_decode_mb_444_complex(h);\n else\n hl_decode_mb_444_simple(h);\n } else if (is_complex) {\n hl_decode_mb_complex(h);\n } else if (h->pixel_shift) {\n hl_decode_mb_simple_16(h);\n } else\n hl_decode_mb_simple_8(h);\n}', 'static void av_noinline hl_decode_mb_444_complex(H264Context *h){\n hl_decode_mb_444_internal(h, 0, h->pixel_shift);\n}', 'static av_always_inline void hl_decode_mb_444_internal(H264Context *h, int simple, int pixel_shift){\n MpegEncContext * const s = &h->s;\n const int mb_x= s->mb_x;\n const int mb_y= s->mb_y;\n const int mb_xy= h->mb_xy;\n const int mb_type= s->current_picture.mb_type[mb_xy];\n uint8_t *dest[3];\n int linesize;\n int i, j, p;\n int *block_offset = &h->block_offset[0];\n const int transform_bypass = !simple && (s->qscale == 0 && h->sps.transform_bypass);\n const int plane_count = (simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)) ? 3 : 1;\n for (p = 0; p < plane_count; p++)\n {\n dest[p] = s->current_picture.data[p] + ((mb_x << pixel_shift) + mb_y * s->linesize) * 16;\n s->dsp.prefetch(dest[p] + (s->mb_x&3)*4*s->linesize + (64 << pixel_shift), s->linesize, 4);\n }\n h->list_counts[mb_xy]= h->list_count;\n if (!simple && MB_FIELD) {\n linesize = h->mb_linesize = h->mb_uvlinesize = s->linesize * 2;\n block_offset = &h->block_offset[48];\n if(mb_y&1)\n for (p = 0; p < 3; p++)\n dest[p] -= s->linesize*15;\n if(FRAME_MBAFF) {\n int list;\n for(list=0; list<h->list_count; list++){\n if(!USES_LIST(mb_type, list))\n continue;\n if(IS_16X16(mb_type)){\n int8_t *ref = &h->ref_cache[list][scan8[0]];\n fill_rectangle(ref, 4, 4, 8, (16+*ref)^(s->mb_y&1), 1);\n }else{\n for(i=0; i<16; i+=4){\n int ref = h->ref_cache[list][scan8[i]];\n if(ref >= 0)\n fill_rectangle(&h->ref_cache[list][scan8[i]], 2, 2, 8, (16+ref)^(s->mb_y&1), 1);\n }\n }\n }\n }\n } else {\n linesize = h->mb_linesize = h->mb_uvlinesize = s->linesize;\n }\n if (!simple && IS_INTRA_PCM(mb_type)) {\n if (pixel_shift) {\n const int bit_depth = h->sps.bit_depth_luma;\n GetBitContext gb;\n init_get_bits(&gb, (uint8_t*)h->mb, 768*bit_depth);\n for (p = 0; p < plane_count; p++) {\n for (i = 0; i < 16; i++) {\n uint16_t *tmp = (uint16_t*)(dest[p] + i*linesize);\n for (j = 0; j < 16; j++)\n tmp[j] = get_bits(&gb, bit_depth);\n }\n }\n } else {\n for (p = 0; p < plane_count; p++) {\n for (i = 0; i < 16; i++) {\n memcpy(dest[p] + i*linesize, h->mb + p*128 + i*8, 16);\n }\n }\n }\n } else {\n if(IS_INTRA(mb_type)){\n if(h->deblocking_filter)\n xchg_mb_border(h, dest[0], dest[1], dest[2], linesize, linesize, 1, 1, simple, pixel_shift);\n for (p = 0; p < plane_count; p++)\n hl_decode_mb_predict_luma(h, mb_type, 1, simple, transform_bypass, pixel_shift, block_offset, linesize, dest[p], p);\n if(h->deblocking_filter)\n xchg_mb_border(h, dest[0], dest[1], dest[2], linesize, linesize, 0, 1, simple, pixel_shift);\n }else{\n hl_motion(h, dest[0], dest[1], dest[2],\n s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab,\n s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab,\n h->h264dsp.weight_h264_pixels_tab,\n h->h264dsp.biweight_h264_pixels_tab, pixel_shift, 1);\n }\n for (p = 0; p < plane_count; p++)\n hl_decode_mb_idct_luma(h, mb_type, 1, simple, transform_bypass, pixel_shift, block_offset, linesize, dest[p], p);\n }\n if(h->cbp || IS_INTRA(mb_type))\n {\n s->dsp.clear_blocks(h->mb);\n s->dsp.clear_blocks(h->mb+(24*16<<pixel_shift));\n }\n}', 'static av_always_inline void hl_motion(H264Context *h, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,\n qpel_mc_func (*qpix_put)[16], h264_chroma_mc_func (*chroma_put),\n qpel_mc_func (*qpix_avg)[16], h264_chroma_mc_func (*chroma_avg),\n h264_weight_func *weight_op, h264_biweight_func *weight_avg,\n int pixel_shift, int chroma444){\n MpegEncContext * const s = &h->s;\n const int mb_xy= h->mb_xy;\n const int mb_type= s->current_picture.mb_type[mb_xy];\n assert(IS_INTER(mb_type));\n if(HAVE_PTHREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))\n await_references(h);\n prefetch_motion(h, 0, pixel_shift, chroma444);\n if(IS_16X16(mb_type)){\n mc_part(h, 0, 1, 8, 0, dest_y, dest_cb, dest_cr, 0, 0,\n qpix_put[0], chroma_put[0], qpix_avg[0], chroma_avg[0],\n weight_op, weight_avg,\n IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1),\n pixel_shift, chroma444);\n }else if(IS_16X8(mb_type)){\n mc_part(h, 0, 0, 4, 8 << pixel_shift, dest_y, dest_cb, dest_cr, 0, 0,\n qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],\n &weight_op[1], &weight_avg[1],\n IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1),\n pixel_shift, chroma444);\n mc_part(h, 8, 0, 4, 8 << pixel_shift, dest_y, dest_cb, dest_cr, 0, 4,\n qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],\n &weight_op[1], &weight_avg[1],\n IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1),\n pixel_shift, chroma444);\n }else if(IS_8X16(mb_type)){\n mc_part(h, 0, 0, 8, 8*h->mb_linesize, dest_y, dest_cb, dest_cr, 0, 0,\n qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],\n &weight_op[2], &weight_avg[2],\n IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1),\n pixel_shift, chroma444);\n mc_part(h, 4, 0, 8, 8*h->mb_linesize, dest_y, dest_cb, dest_cr, 4, 0,\n qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],\n &weight_op[2], &weight_avg[2],\n IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1),\n pixel_shift, chroma444);\n }else{\n int i;\n assert(IS_8X8(mb_type));\n for(i=0; i<4; i++){\n const int sub_mb_type= h->sub_mb_type[i];\n const int n= 4*i;\n int x_offset= (i&1)<<2;\n int y_offset= (i&2)<<1;\n if(IS_SUB_8X8(sub_mb_type)){\n mc_part(h, n, 1, 4, 0, dest_y, dest_cb, dest_cr, x_offset, y_offset,\n qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],\n &weight_op[3], &weight_avg[3],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma444);\n }else if(IS_SUB_8X4(sub_mb_type)){\n mc_part(h, n , 0, 2, 4 << pixel_shift, dest_y, dest_cb, dest_cr, x_offset, y_offset,\n qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],\n &weight_op[4], &weight_avg[4],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma444);\n mc_part(h, n+2, 0, 2, 4 << pixel_shift, dest_y, dest_cb, dest_cr, x_offset, y_offset+2,\n qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],\n &weight_op[4], &weight_avg[4],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma444);\n }else if(IS_SUB_4X8(sub_mb_type)){\n mc_part(h, n , 0, 4, 4*h->mb_linesize, dest_y, dest_cb, dest_cr, x_offset, y_offset,\n qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],\n &weight_op[5], &weight_avg[5],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma444);\n mc_part(h, n+1, 0, 4, 4*h->mb_linesize, dest_y, dest_cb, dest_cr, x_offset+2, y_offset,\n qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],\n &weight_op[5], &weight_avg[5],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma444);\n }else{\n int j;\n assert(IS_SUB_4X4(sub_mb_type));\n for(j=0; j<4; j++){\n int sub_x_offset= x_offset + 2*(j&1);\n int sub_y_offset= y_offset + (j&2);\n mc_part(h, n+j, 1, 2, 0, dest_y, dest_cb, dest_cr, sub_x_offset, sub_y_offset,\n qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],\n &weight_op[6], &weight_avg[6],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma444);\n }\n }\n }\n }\n prefetch_motion(h, 1, pixel_shift, chroma444);\n}', 'static void await_references(H264Context *h){\n MpegEncContext * const s = &h->s;\n const int mb_xy= h->mb_xy;\n const int mb_type= s->current_picture.mb_type[mb_xy];\n int refs[2][48];\n int nrefs[2] = {0};\n int ref, list;\n memset(refs, -1, sizeof(refs));\n if(IS_16X16(mb_type)){\n get_lowest_part_y(h, refs, 0, 16, 0,\n IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);\n }else if(IS_16X8(mb_type)){\n get_lowest_part_y(h, refs, 0, 8, 0,\n IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);\n get_lowest_part_y(h, refs, 8, 8, 8,\n IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs);\n }else if(IS_8X16(mb_type)){\n get_lowest_part_y(h, refs, 0, 16, 0,\n IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);\n get_lowest_part_y(h, refs, 4, 16, 0,\n IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs);\n }else{\n int i;\n assert(IS_8X8(mb_type));\n for(i=0; i<4; i++){\n const int sub_mb_type= h->sub_mb_type[i];\n const int n= 4*i;\n int y_offset= (i&2)<<2;\n if(IS_SUB_8X8(sub_mb_type)){\n get_lowest_part_y(h, refs, n , 8, y_offset,\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n }else if(IS_SUB_8X4(sub_mb_type)){\n get_lowest_part_y(h, refs, n , 4, y_offset,\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n get_lowest_part_y(h, refs, n+2, 4, y_offset+4,\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n }else if(IS_SUB_4X8(sub_mb_type)){\n get_lowest_part_y(h, refs, n , 8, y_offset,\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n get_lowest_part_y(h, refs, n+1, 8, y_offset,\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n }else{\n int j;\n assert(IS_SUB_4X4(sub_mb_type));\n for(j=0; j<4; j++){\n int sub_y_offset= y_offset + 2*(j&2);\n get_lowest_part_y(h, refs, n+j, 4, sub_y_offset,\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n }\n }\n }\n }\n for(list=h->list_count-1; list>=0; list--){\n for(ref=0; ref<48 && nrefs[list]; ref++){\n int row = refs[list][ref];\n if(row >= 0){\n Picture *ref_pic = &h->ref_list[list][ref];\n int ref_field = ref_pic->reference - 1;\n int ref_field_picture = ref_pic->field_picture;\n int pic_height = 16*s->mb_height >> ref_field_picture;\n row <<= MB_MBAFF;\n nrefs[list]--;\n if(!FIELD_PICTURE && ref_field_picture){\n ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1) - !(row&1), pic_height-1), 1);\n ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1) , pic_height-1), 0);\n }else if(FIELD_PICTURE && !ref_field_picture){\n ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row*2 + ref_field , pic_height-1), 0);\n }else if(FIELD_PICTURE){\n ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), ref_field);\n }else{\n ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), 0);\n }\n }\n }\n }\n}']
34,808
0
https://github.com/openssl/openssl/blob/270a4bba49849de7f928f4fab186205abd132411/crypto/objects/o_names.c/#L132
int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *), int (*cmp_func) (const char *, const char *), void (*free_func) (const char *, int, const char *)) { int ret = 0, i, push; NAME_FUNCS *name_funcs; if (!OBJ_NAME_init()) return 0; CRYPTO_THREAD_write_lock(obj_lock); if (name_funcs_stack == NULL) { CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE); name_funcs_stack = sk_NAME_FUNCS_new_null(); CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE); } if (name_funcs_stack == NULL) { goto out; } ret = names_type_num; names_type_num++; for (i = sk_NAME_FUNCS_num(name_funcs_stack); i < names_type_num; i++) { CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE); name_funcs = OPENSSL_zalloc(sizeof(*name_funcs)); CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE); if (name_funcs == NULL) { OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE); ret = 0; goto out; } name_funcs->hash_func = OPENSSL_LH_strhash; name_funcs->cmp_func = obj_strcmp; CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE); push = sk_NAME_FUNCS_push(name_funcs_stack, name_funcs); CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE); if (!push) { OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE); OPENSSL_free(name_funcs); ret = 0; goto out; } } name_funcs = sk_NAME_FUNCS_value(name_funcs_stack, ret); if (hash_func != NULL) name_funcs->hash_func = hash_func; if (cmp_func != NULL) name_funcs->cmp_func = cmp_func; if (free_func != NULL) name_funcs->free_func = free_func; out: CRYPTO_THREAD_unlock(obj_lock); return ret; }
['int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *),\n int (*cmp_func) (const char *, const char *),\n void (*free_func) (const char *, int, const char *))\n{\n int ret = 0, i, push;\n NAME_FUNCS *name_funcs;\n if (!OBJ_NAME_init())\n return 0;\n CRYPTO_THREAD_write_lock(obj_lock);\n if (name_funcs_stack == NULL) {\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);\n name_funcs_stack = sk_NAME_FUNCS_new_null();\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);\n }\n if (name_funcs_stack == NULL) {\n goto out;\n }\n ret = names_type_num;\n names_type_num++;\n for (i = sk_NAME_FUNCS_num(name_funcs_stack); i < names_type_num; i++) {\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);\n name_funcs = OPENSSL_zalloc(sizeof(*name_funcs));\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);\n if (name_funcs == NULL) {\n OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE);\n ret = 0;\n goto out;\n }\n name_funcs->hash_func = OPENSSL_LH_strhash;\n name_funcs->cmp_func = obj_strcmp;\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);\n push = sk_NAME_FUNCS_push(name_funcs_stack, name_funcs);\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);\n if (!push) {\n OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE);\n OPENSSL_free(name_funcs);\n ret = 0;\n goto out;\n }\n }\n name_funcs = sk_NAME_FUNCS_value(name_funcs_stack, ret);\n if (hash_func != NULL)\n name_funcs->hash_func = hash_func;\n if (cmp_func != NULL)\n name_funcs->cmp_func = cmp_func;\n if (free_func != NULL)\n name_funcs->free_func = free_func;\nout:\n CRYPTO_THREAD_unlock(obj_lock);\n return ret;\n}', 'int OBJ_NAME_init(void)\n{\n return RUN_ONCE(&init, o_names_init);\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n if (pthread_once(once, init) != 0)\n return 0;\n return 1;\n}', 'int CRYPTO_THREAD_write_lock(CRYPTO_RWLOCK *lock)\n{\n# ifdef USE_RWLOCK\n if (pthread_rwlock_wrlock(lock) != 0)\n return 0;\n# else\n if (pthread_mutex_lock(lock) != 0)\n return 0;\n# endif\n return 1;\n}', 'int CRYPTO_mem_ctrl(int mode)\n{\n#ifdef OPENSSL_NO_CRYPTO_MDEBUG\n return mode - mode;\n#else\n int ret = mh_mode;\n if (!RUN_ONCE(&memdbg_init, do_memdbg_init))\n return -1;\n CRYPTO_THREAD_write_lock(malloc_lock);\n switch (mode) {\n default:\n break;\n case CRYPTO_MEM_CHECK_ON:\n mh_mode = CRYPTO_MEM_CHECK_ON | CRYPTO_MEM_CHECK_ENABLE;\n num_disable = 0;\n break;\n case CRYPTO_MEM_CHECK_OFF:\n mh_mode = 0;\n num_disable = 0;\n break;\n case CRYPTO_MEM_CHECK_DISABLE:\n if (mh_mode & CRYPTO_MEM_CHECK_ON) {\n CRYPTO_THREAD_ID cur = CRYPTO_THREAD_get_current_id();\n if (!num_disable\n || !CRYPTO_THREAD_compare_id(disabling_threadid, cur)) {\n CRYPTO_THREAD_unlock(malloc_lock);\n CRYPTO_THREAD_write_lock(long_malloc_lock);\n CRYPTO_THREAD_write_lock(malloc_lock);\n mh_mode &= ~CRYPTO_MEM_CHECK_ENABLE;\n disabling_threadid = cur;\n }\n num_disable++;\n }\n break;\n case CRYPTO_MEM_CHECK_ENABLE:\n if (mh_mode & CRYPTO_MEM_CHECK_ON) {\n if (num_disable) {\n num_disable--;\n if (num_disable == 0) {\n mh_mode |= CRYPTO_MEM_CHECK_ENABLE;\n CRYPTO_THREAD_unlock(long_malloc_lock);\n }\n }\n }\n break;\n }\n CRYPTO_THREAD_unlock(malloc_lock);\n return ret;\n#endif\n}', 'OPENSSL_STACK *OPENSSL_sk_new_null(void)\n{\n return OPENSSL_zalloc(sizeof(OPENSSL_STACK));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'int OPENSSL_sk_num(const OPENSSL_STACK *st)\n{\n if (st == NULL)\n return -1;\n return st->num;\n}', 'void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)\n{\n if (st == NULL || i < 0 || i >= st->num)\n return NULL;\n return (void *)st->data[i];\n}']
34,809
0
https://github.com/openssl/openssl/blob/183733f882056ea3e6fe95e665b85fcc6a45dcb4/crypto/x509/x_x509a.c/#L184
int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj) { X509_CERT_AUX *aux; ASN1_OBJECT *objtmp; if ((objtmp = OBJ_dup(obj)) == NULL) return 0; if ((aux = aux_get(x)) == NULL) goto err; if (aux->reject == NULL && (aux->reject = sk_ASN1_OBJECT_new_null()) == NULL) goto err; return sk_ASN1_OBJECT_push(aux->reject, objtmp); err: ASN1_OBJECT_free(objtmp); return 0; }
['int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj)\n{\n X509_CERT_AUX *aux;\n ASN1_OBJECT *objtmp;\n if ((objtmp = OBJ_dup(obj)) == NULL)\n return 0;\n if ((aux = aux_get(x)) == NULL)\n goto err;\n if (aux->reject == NULL\n && (aux->reject = sk_ASN1_OBJECT_new_null()) == NULL)\n goto err;\n return sk_ASN1_OBJECT_push(aux->reject, objtmp);\n err:\n ASN1_OBJECT_free(objtmp);\n return 0;\n}', 'ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o)\n{\n ASN1_OBJECT *r;\n int i;\n char *ln = NULL, *sn = NULL;\n unsigned char *data = NULL;\n if (o == NULL)\n return (NULL);\n if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC))\n return ((ASN1_OBJECT *)o);\n r = ASN1_OBJECT_new();\n if (r == NULL) {\n OBJerr(OBJ_F_OBJ_DUP, ERR_R_ASN1_LIB);\n return (NULL);\n }\n data = OPENSSL_malloc(o->length);\n if (data == NULL)\n goto err;\n if (o->data != NULL)\n memcpy(data, o->data, o->length);\n r->data = data;\n r->length = o->length;\n r->nid = o->nid;\n r->ln = r->sn = NULL;\n if (o->ln != NULL) {\n i = strlen(o->ln) + 1;\n ln = OPENSSL_malloc(i);\n if (ln == NULL)\n goto err;\n memcpy(ln, o->ln, i);\n r->ln = ln;\n }\n if (o->sn != NULL) {\n i = strlen(o->sn) + 1;\n sn = OPENSSL_malloc(i);\n if (sn == NULL)\n goto err;\n memcpy(sn, o->sn, i);\n r->sn = sn;\n }\n r->flags = o->flags | (ASN1_OBJECT_FLAG_DYNAMIC |\n ASN1_OBJECT_FLAG_DYNAMIC_STRINGS |\n ASN1_OBJECT_FLAG_DYNAMIC_DATA);\n return (r);\n err:\n OBJerr(OBJ_F_OBJ_DUP, ERR_R_MALLOC_FAILURE);\n OPENSSL_free(ln);\n OPENSSL_free(sn);\n OPENSSL_free(data);\n OPENSSL_free(r);\n return (NULL);\n}', 'ASN1_OBJECT *ASN1_OBJECT_new(void)\n{\n ASN1_OBJECT *ret;\n ret = OPENSSL_zalloc(sizeof(*ret));\n if (ret == NULL) {\n ASN1err(ASN1_F_ASN1_OBJECT_NEW, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n ret->flags = ASN1_OBJECT_FLAG_DYNAMIC;\n return (ret);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}', 'static X509_CERT_AUX *aux_get(X509 *x)\n{\n if (x == NULL)\n return NULL;\n if (x->aux == NULL && (x->aux = X509_CERT_AUX_new()) == NULL)\n return NULL;\n return x->aux;\n}', 'DEFINE_STACK_OF(ASN1_OBJECT)', 'int sk_push(_STACK *st, void *data)\n{\n return (sk_insert(st, data, st->num));\n}', 'int sk_insert(_STACK *st, void *data, int loc)\n{\n char **s;\n if (st == NULL)\n return 0;\n if (st->num_alloc <= st->num + 1) {\n s = OPENSSL_realloc((char *)st->data,\n (unsigned int)sizeof(char *) * st->num_alloc * 2);\n if (s == NULL)\n return (0);\n st->data = s;\n st->num_alloc *= 2;\n }\n if ((loc >= (int)st->num) || (loc < 0))\n st->data[st->num] = data;\n else {\n memmove(&(st->data[loc + 1]),\n &(st->data[loc]), sizeof(char *) * (st->num - loc));\n st->data[loc] = data;\n }\n st->num++;\n st->sorted = 0;\n return (st->num);\n}', 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n if (str == NULL)\n return CRYPTO_malloc(num, file, line);\n if (num == 0) {\n CRYPTO_free(str);\n return NULL;\n }\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n void *ret;\n CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);\n ret = realloc(str, num);\n CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);\n return ret;\n }\n#else\n (void)file;\n (void)line;\n#endif\n return realloc(str, num);\n}']
34,810
0
https://github.com/libav/libav/blob/fc322d6a70189da24dbd445c710bb214eb031ce7/libavcodec/bitstream.h/#L139
static inline uint64_t get_val(BitstreamContext *bc, unsigned n) { #ifdef BITSTREAM_READER_LE uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1); bc->bits >>= n; #else uint64_t ret = bc->bits >> (64 - n); bc->bits <<= n; #endif bc->bits_left -= n; return ret; }
['static int read_restart_header(MLPDecodeContext *m, BitstreamContext *bc,\n const uint8_t *buf, unsigned int substr)\n{\n SubStream *s = &m->substream[substr];\n unsigned int ch;\n int sync_word, tmp;\n uint8_t checksum;\n uint8_t lossless_check;\n int start_count = bitstream_tell(bc);\n int min_channel, max_channel, max_matrix_channel;\n const int std_max_matrix_channel = m->avctx->codec_id == AV_CODEC_ID_MLP\n ? MAX_MATRIX_CHANNEL_MLP\n : MAX_MATRIX_CHANNEL_TRUEHD;\n sync_word = bitstream_read(bc, 13);\n if (sync_word != 0x31ea >> 1) {\n av_log(m->avctx, AV_LOG_ERROR,\n "restart header sync incorrect (got 0x%04x)\\n", sync_word);\n return AVERROR_INVALIDDATA;\n }\n s->noise_type = bitstream_read_bit(bc);\n if (m->avctx->codec_id == AV_CODEC_ID_MLP && s->noise_type) {\n av_log(m->avctx, AV_LOG_ERROR, "MLP must have 0x31ea sync word.\\n");\n return AVERROR_INVALIDDATA;\n }\n bitstream_skip(bc, 16);\n min_channel = bitstream_read(bc, 4);\n max_channel = bitstream_read(bc, 4);\n max_matrix_channel = bitstream_read(bc, 4);\n if (max_matrix_channel > std_max_matrix_channel) {\n av_log(m->avctx, AV_LOG_ERROR,\n "Max matrix channel cannot be greater than %d.\\n",\n max_matrix_channel);\n return AVERROR_INVALIDDATA;\n }\n if (max_channel != max_matrix_channel) {\n av_log(m->avctx, AV_LOG_ERROR,\n "Max channel must be equal max matrix channel.\\n");\n return AVERROR_INVALIDDATA;\n }\n if (s->max_channel > MAX_MATRIX_CHANNEL_MLP && !s->noise_type) {\n avpriv_request_sample(m->avctx,\n "%d channels (more than the "\n "maximum supported by the decoder)",\n s->max_channel + 2);\n return AVERROR_PATCHWELCOME;\n }\n if (min_channel > max_channel) {\n av_log(m->avctx, AV_LOG_ERROR,\n "Substream min channel cannot be greater than max channel.\\n");\n return AVERROR_INVALIDDATA;\n }\n s->min_channel = min_channel;\n s->max_channel = max_channel;\n s->max_matrix_channel = max_matrix_channel;\n if (m->avctx->request_channel_layout && (s->ch_layout & m->avctx->request_channel_layout) ==\n m->avctx->request_channel_layout && m->max_decoded_substream > substr) {\n av_log(m->avctx, AV_LOG_DEBUG,\n "Extracting %d-channel downmix (0x%"PRIx64") from substream %d. "\n "Further substreams will be skipped.\\n",\n s->max_channel + 1, s->ch_layout, substr);\n m->max_decoded_substream = substr;\n }\n s->noise_shift = bitstream_read(bc, 4);\n s->noisegen_seed = bitstream_read(bc, 23);\n bitstream_skip(bc, 19);\n s->data_check_present = bitstream_read_bit(bc);\n lossless_check = bitstream_read(bc, 8);\n if (substr == m->max_decoded_substream\n && s->lossless_check_data != 0xffffffff) {\n tmp = xor_32_to_8(s->lossless_check_data);\n if (tmp != lossless_check)\n av_log(m->avctx, AV_LOG_WARNING,\n "Lossless check failed - expected %02x, calculated %02x.\\n",\n lossless_check, tmp);\n }\n bitstream_skip(bc, 16);\n memset(s->ch_assign, 0, sizeof(s->ch_assign));\n for (ch = 0; ch <= s->max_matrix_channel; ch++) {\n int ch_assign = bitstream_read(bc, 6);\n if (m->avctx->codec_id == AV_CODEC_ID_TRUEHD) {\n uint64_t channel = thd_channel_layout_extract_channel(s->ch_layout,\n ch_assign);\n ch_assign = av_get_channel_layout_channel_index(s->ch_layout,\n channel);\n }\n if (ch_assign < 0 || ch_assign > s->max_matrix_channel) {\n avpriv_request_sample(m->avctx,\n "Assignment of matrix channel %d to invalid output channel %d",\n ch, ch_assign);\n return AVERROR_PATCHWELCOME;\n }\n s->ch_assign[ch_assign] = ch;\n }\n checksum = ff_mlp_restart_checksum(buf, bitstream_tell(bc) - start_count);\n if (checksum != bitstream_read(bc, 8))\n av_log(m->avctx, AV_LOG_ERROR, "restart header checksum error\\n");\n s->param_presence_flags = 0xff;\n s->num_primitive_matrices = 0;\n s->blocksize = 8;\n s->lossless_check_data = 0;\n memset(s->output_shift , 0, sizeof(s->output_shift ));\n memset(s->quant_step_size, 0, sizeof(s->quant_step_size));\n for (ch = s->min_channel; ch <= s->max_channel; ch++) {\n ChannelParams *cp = &s->channel_params[ch];\n cp->filter_params[FIR].order = 0;\n cp->filter_params[IIR].order = 0;\n cp->filter_params[FIR].shift = 0;\n cp->filter_params[IIR].shift = 0;\n cp->huff_offset = 0;\n cp->sign_huff_offset = -(1 << 23);\n cp->codebook = 0;\n cp->huff_lsbs = 24;\n }\n if (substr == m->max_decoded_substream) {\n m->avctx->channels = s->max_matrix_channel + 1;\n m->avctx->channel_layout = s->ch_layout;\n m->dsp.mlp_pack_output = m->dsp.mlp_select_pack_output(s->ch_assign,\n s->output_shift,\n s->max_matrix_channel,\n m->avctx->sample_fmt == AV_SAMPLE_FMT_S32);\n }\n return 0;\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n if (!n)\n return 0;\n if (n > bc->bits_left) {\n refill_32(bc);\n if (bc->bits_left < 32)\n bc->bits_left = n;\n }\n return get_val(bc, n);\n}', 'static inline uint64_t get_val(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);\n bc->bits >>= n;\n#else\n uint64_t ret = bc->bits >> (64 - n);\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n return ret;\n}']
34,811
0
https://github.com/openssl/openssl/blob/c15e95a61dacfc326cf9cdf05935ae8c6c97bcf6/crypto/x509/x509_lu.c/#L346
int X509_STORE_add_cert(X509_STORE *ctx, X509 *x) { X509_OBJECT *obj; int ret = 1; if (x == NULL) return 0; obj = OPENSSL_malloc(sizeof(*obj)); if (obj == NULL) { X509err(X509_F_X509_STORE_ADD_CERT, ERR_R_MALLOC_FAILURE); return 0; } obj->type = X509_LU_X509; obj->data.x509 = x; CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); X509_OBJECT_up_ref_count(obj); if (X509_OBJECT_retrieve_match(ctx->objs, obj)) { X509_OBJECT_free_contents(obj); OPENSSL_free(obj); X509err(X509_F_X509_STORE_ADD_CERT, X509_R_CERT_ALREADY_IN_HASH_TABLE); ret = 0; } else sk_X509_OBJECT_push(ctx->objs, obj); CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); return ret; }
['int X509_STORE_add_cert(X509_STORE *ctx, X509 *x)\n{\n X509_OBJECT *obj;\n int ret = 1;\n if (x == NULL)\n return 0;\n obj = OPENSSL_malloc(sizeof(*obj));\n if (obj == NULL) {\n X509err(X509_F_X509_STORE_ADD_CERT, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n obj->type = X509_LU_X509;\n obj->data.x509 = x;\n CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);\n X509_OBJECT_up_ref_count(obj);\n if (X509_OBJECT_retrieve_match(ctx->objs, obj)) {\n X509_OBJECT_free_contents(obj);\n OPENSSL_free(obj);\n X509err(X509_F_X509_STORE_ADD_CERT,\n X509_R_CERT_ALREADY_IN_HASH_TABLE);\n ret = 0;\n } else\n sk_X509_OBJECT_push(ctx->objs, obj);\n CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}', 'void CRYPTO_lock(int mode, int type, const char *file, int line)\n{\n#ifdef LOCK_DEBUG\n {\n CRYPTO_THREADID id;\n char *rw_text, *operation_text;\n if (mode & CRYPTO_LOCK)\n operation_text = "lock ";\n else if (mode & CRYPTO_UNLOCK)\n operation_text = "unlock";\n else\n operation_text = "ERROR ";\n if (mode & CRYPTO_READ)\n rw_text = "r";\n else if (mode & CRYPTO_WRITE)\n rw_text = "w";\n else\n rw_text = "ERROR";\n CRYPTO_THREADID_current(&id);\n fprintf(stderr, "lock:%08lx:(%s)%s %-18s %s:%d\\n",\n CRYPTO_THREADID_hash(&id), rw_text, operation_text,\n CRYPTO_get_lock_name(type), file, line);\n }\n#endif\n if (type < 0) {\n if (dynlock_lock_callback != NULL) {\n struct CRYPTO_dynlock_value *pointer\n = CRYPTO_get_dynlock_value(type);\n OPENSSL_assert(pointer != NULL);\n dynlock_lock_callback(mode, pointer, file, line);\n CRYPTO_destroy_dynlockid(type);\n }\n } else if (locking_callback != NULL)\n locking_callback(mode, type, file, line);\n}', 'void X509_OBJECT_up_ref_count(X509_OBJECT *a)\n{\n switch (a->type) {\n default:\n break;\n case X509_LU_X509:\n X509_up_ref(a->data.x509);\n break;\n case X509_LU_CRL:\n X509_CRL_up_ref(a->data.crl);\n break;\n }\n}', 'void X509_up_ref(X509 *x)\n{\n CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509);\n}', 'int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,\n int line)\n{\n int ret = 0;\n if (add_lock_callback != NULL) {\n#ifdef LOCK_DEBUG\n int before = *pointer;\n#endif\n ret = add_lock_callback(pointer, amount, type, file, line);\n#ifdef LOCK_DEBUG\n {\n CRYPTO_THREADID id;\n CRYPTO_THREADID_current(&id);\n fprintf(stderr, "ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\\n",\n CRYPTO_THREADID_hash(&id), before, amount, ret,\n CRYPTO_get_lock_name(type), file, line);\n }\n#endif\n } else {\n CRYPTO_lock(CRYPTO_LOCK | CRYPTO_WRITE, type, file, line);\n ret = *pointer + amount;\n#ifdef LOCK_DEBUG\n {\n CRYPTO_THREADID id;\n CRYPTO_THREADID_current(&id);\n fprintf(stderr, "ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\\n",\n CRYPTO_THREADID_hash(&id),\n *pointer, amount, ret,\n CRYPTO_get_lock_name(type), file, line);\n }\n#endif\n *pointer = ret;\n CRYPTO_lock(CRYPTO_UNLOCK | CRYPTO_WRITE, type, file, line);\n }\n return (ret);\n}', 'int sk_push(_STACK *st, void *data)\n{\n return (sk_insert(st, data, st->num));\n}', 'int sk_insert(_STACK *st, void *data, int loc)\n{\n char **s;\n if (st == NULL)\n return 0;\n if (st->num_alloc <= st->num + 1) {\n s = OPENSSL_realloc((char *)st->data,\n (unsigned int)sizeof(char *) * st->num_alloc * 2);\n if (s == NULL)\n return (0);\n st->data = s;\n st->num_alloc *= 2;\n }\n if ((loc >= (int)st->num) || (loc < 0))\n st->data[st->num] = data;\n else {\n memmove(&(st->data[loc + 1]),\n &(st->data[loc]), sizeof(char *) * (st->num - loc));\n st->data[loc] = data;\n }\n st->num++;\n st->sorted = 0;\n return (st->num);\n}', 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n if (str == NULL)\n return CRYPTO_malloc(num, file, line);\n if (num == 0) {\n CRYPTO_free(str);\n return NULL;\n }\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n void *ret;\n CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);\n ret = realloc(str, num);\n CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);\n return ret;\n }\n#else\n (void)file;\n (void)line;\n#endif\n return realloc(str, num);\n}']
34,812
0
https://github.com/libav/libav/blob/06d37fede4d36ea528ef69e4358a5775df016df0/ffmpeg.c/#L2861
static int opt_metadata(const char *opt, const char *arg) { char *mid= strchr(arg, '='); if(!mid){ fprintf(stderr, "Missing =\n"); ffmpeg_exit(1); } *mid++= 0; av_dict_set(&metadata, arg, mid, 0); return 0; }
['static int opt_metadata(const char *opt, const char *arg)\n{\n char *mid= strchr(arg, \'=\');\n if(!mid){\n fprintf(stderr, "Missing =\\n");\n ffmpeg_exit(1);\n }\n *mid++= 0;\n av_dict_set(&metadata, arg, mid, 0);\n return 0;\n}']
34,813
0
https://github.com/openssl/openssl/blob/d6a03a23a8552070591784935d5aee949d5b9623/apps/apps.c/#L1075
static EVP_PKEY * load_netscape_key(BIO *err, BIO *key, const char *file, const char *key_descrip, int format) { EVP_PKEY *pkey; BUF_MEM *buf; RSA *rsa; const unsigned char *p; int size, i; buf=BUF_MEM_new(); pkey = EVP_PKEY_new(); size = 0; if (buf == NULL || pkey == NULL) goto error; for (;;) { if (!BUF_MEM_grow_clean(buf,size+1024*10)) goto error; i = BIO_read(key, &(buf->data[size]), 1024*10); size += i; if (i == 0) break; if (i < 0) { BIO_printf(err, "Error reading %s %s", key_descrip, file); goto error; } } p=(unsigned char *)buf->data; rsa = d2i_RSA_NET(NULL,&p,(long)size,NULL, (format == FORMAT_IISSGC ? 1 : 0)); if (rsa == NULL) goto error; BUF_MEM_free(buf); EVP_PKEY_set1_RSA(pkey, rsa); return pkey; error: BUF_MEM_free(buf); EVP_PKEY_free(pkey); return NULL; }
['static EVP_PKEY *\nload_netscape_key(BIO *err, BIO *key, const char *file,\n\t\tconst char *key_descrip, int format)\n\t{\n\tEVP_PKEY *pkey;\n\tBUF_MEM *buf;\n\tRSA\t*rsa;\n\tconst unsigned char *p;\n\tint size, i;\n\tbuf=BUF_MEM_new();\n\tpkey = EVP_PKEY_new();\n\tsize = 0;\n\tif (buf == NULL || pkey == NULL)\n\t\tgoto error;\n\tfor (;;)\n\t\t{\n\t\tif (!BUF_MEM_grow_clean(buf,size+1024*10))\n\t\t\tgoto error;\n\t\ti = BIO_read(key, &(buf->data[size]), 1024*10);\n\t\tsize += i;\n\t\tif (i == 0)\n\t\t\tbreak;\n\t\tif (i < 0)\n\t\t\t{\n\t\t\t\tBIO_printf(err, "Error reading %s %s",\n\t\t\t\t\tkey_descrip, file);\n\t\t\t\tgoto error;\n\t\t\t}\n\t\t}\n\tp=(unsigned char *)buf->data;\n\trsa = d2i_RSA_NET(NULL,&p,(long)size,NULL,\n\t\t(format == FORMAT_IISSGC ? 1 : 0));\n\tif (rsa == NULL)\n\t\tgoto error;\n\tBUF_MEM_free(buf);\n\tEVP_PKEY_set1_RSA(pkey, rsa);\n\treturn pkey;\nerror:\n\tBUF_MEM_free(buf);\n\tEVP_PKEY_free(pkey);\n\treturn NULL;\n\t}', 'BUF_MEM *BUF_MEM_new(void)\n\t{\n\tBUF_MEM *ret;\n\tret=OPENSSL_malloc(sizeof(BUF_MEM));\n\tif (ret == NULL)\n\t\t{\n\t\tBUFerr(BUF_F_BUF_MEM_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->length=0;\n\tret->max=0;\n\tret->data=NULL;\n\treturn(ret);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\textern unsigned char cleanse_ctr;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n if(ret && (num > 2048))\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\treturn ret;\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_flags[es->top]=0;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}', 'EVP_PKEY *EVP_PKEY_new(void)\n\t{\n\tEVP_PKEY *ret;\n\tret=(EVP_PKEY *)OPENSSL_malloc(sizeof(EVP_PKEY));\n\tif (ret == NULL)\n\t\t{\n\t\tEVPerr(EVP_F_EVP_PKEY_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->type=EVP_PKEY_NONE;\n\tret->references=1;\n\tret->pkey.ptr=NULL;\n\tret->attributes=NULL;\n\tret->save_parameters=1;\n\treturn(ret);\n\t}', 'void BUF_MEM_free(BUF_MEM *a)\n\t{\n\tif(a == NULL)\n\t return;\n\tif (a->data != NULL)\n\t\t{\n\t\tmemset(a->data,0,(unsigned int)a->max);\n\t\tOPENSSL_free(a->data);\n\t\t}\n\tOPENSSL_free(a);\n\t}']
34,814
0
https://github.com/apache/httpd/blob/c25b89a72006389fa9c651a7325e020374fc3edd/srclib/pcre/pcre.c/#L2935
pcre * pcre_compile(const char *pattern, int options, const char **errorptr, int *erroroffset, const unsigned char *tables) { real_pcre *re; int length = 3; int runlength; int c, reqchar, countlits; int bracount = 0; int top_backref = 0; int branch_extra = 0; int branch_newextra; unsigned int brastackptr = 0; size_t size; uschar *code; const uschar *ptr; compile_data compile_block; int brastack[BRASTACK_SIZE]; uschar bralenstack[BRASTACK_SIZE]; #ifdef DEBUG uschar *code_base, *code_end; #endif #ifndef SUPPORT_UTF8 if ((options & PCRE_UTF8) != 0) { *errorptr = ERR32; return NULL; } #endif if (errorptr == NULL) return NULL; *errorptr = NULL; if (erroroffset == NULL) { *errorptr = ERR16; return NULL; } *erroroffset = 0; if ((options & ~PUBLIC_OPTIONS) != 0) { *errorptr = ERR17; return NULL; } if (tables == NULL) tables = pcre_default_tables; compile_block.lcc = tables + lcc_offset; compile_block.fcc = tables + fcc_offset; compile_block.cbits = tables + cbits_offset; compile_block.ctypes = tables + ctypes_offset; DPRINTF(("------------------------------------------------------------------\n")); DPRINTF(("%s\n", pattern)); ptr = (const uschar *)(pattern - 1); while ((c = *(++ptr)) != 0) { int min, max; int class_charcount; int bracket_length; if ((options & PCRE_EXTENDED) != 0) { if ((compile_block.ctypes[c] & ctype_space) != 0) continue; if (c == '#') { while ((c = *(++ptr)) != 0 && c != NEWLINE) ; continue; } } switch(c) { case '\\': { const uschar *save_ptr = ptr; c = check_escape(&ptr, errorptr, bracount, options, FALSE, &compile_block); if (*errorptr != NULL) goto PCRE_ERROR_RETURN; if (c >= 0) { ptr = save_ptr; c = '\\'; goto NORMAL_CHAR; } } length++; if (c <= -ESC_REF) { int refnum = -c - ESC_REF; if (refnum > top_backref) top_backref = refnum; length += 2; if (ptr[1] == '{' && is_counted_repeat(ptr+2, &compile_block)) { ptr = read_repeat_counts(ptr+2, &min, &max, errorptr, &compile_block); if (*errorptr != NULL) goto PCRE_ERROR_RETURN; if ((min == 0 && (max == 1 || max == -1)) || (min == 1 && max == -1)) length++; else length += 5; if (ptr[1] == '?') ptr++; } } continue; case '^': case '.': case '$': case '*': case '+': case '?': length++; continue; case '{': if (!is_counted_repeat(ptr+1, &compile_block)) goto NORMAL_CHAR; ptr = read_repeat_counts(ptr+1, &min, &max, errorptr, &compile_block); if (*errorptr != NULL) goto PCRE_ERROR_RETURN; if ((min == 0 && (max == 1 || max == -1)) || (min == 1 && max == -1)) length++; else { length--; if (min == 1) length++; else if (min > 0) length += 4; if (max > 0) length += 4; else length += 2; } if (ptr[1] == '?') ptr++; continue; case '|': length += 3 + branch_extra; continue; case '[': class_charcount = 0; if (*(++ptr) == '^') ptr++; do { if (*ptr == '\\') { int ch = check_escape(&ptr, errorptr, bracount, options, TRUE, &compile_block); if (*errorptr != NULL) goto PCRE_ERROR_RETURN; if (-ch == ESC_b) class_charcount++; else class_charcount = 10; } else class_charcount++; ptr++; } while (*ptr != 0 && *ptr != ']'); if (class_charcount == 1) length += 3; else { length += 33; if (*ptr != 0 && ptr[1] == '{' && is_counted_repeat(ptr+2, &compile_block)) { ptr = read_repeat_counts(ptr+2, &min, &max, errorptr, &compile_block); if (*errorptr != NULL) goto PCRE_ERROR_RETURN; if ((min == 0 && (max == 1 || max == -1)) || (min == 1 && max == -1)) length++; else length += 5; if (ptr[1] == '?') ptr++; } } continue; case '(': branch_newextra = 0; bracket_length = 3; if (ptr[1] == '?') { int set, unset; int *optset; switch (c = ptr[2]) { case '#': ptr += 3; while (*ptr != 0 && *ptr != ')') ptr++; if (*ptr == 0) { *errorptr = ERR18; goto PCRE_ERROR_RETURN; } continue; case ':': case '=': case '!': case '>': ptr += 2; break; case 'R': if (ptr[3] != ')') { *errorptr = ERR29; goto PCRE_ERROR_RETURN; } ptr += 3; length += 1; break; case '<': if (ptr[3] == '=' || ptr[3] == '!') { ptr += 3; branch_newextra = 3; length += 3; break; } *errorptr = ERR24; goto PCRE_ERROR_RETURN; case '(': if ((compile_block.ctypes[ptr[3]] & ctype_digit) != 0) { ptr += 4; length += 3; while ((compile_block.ctypes[*ptr] & ctype_digit) != 0) ptr++; if (*ptr != ')') { *errorptr = ERR26; goto PCRE_ERROR_RETURN; } } else { ptr++; if (ptr[2] != '?' || (ptr[3] != '=' && ptr[3] != '!' && ptr[3] != '<') ) { ptr += 2; *errorptr = ERR28; goto PCRE_ERROR_RETURN; } } break; default: set = unset = 0; optset = &set; ptr += 2; for (;; ptr++) { c = *ptr; switch (c) { case 'i': *optset |= PCRE_CASELESS; continue; case 'm': *optset |= PCRE_MULTILINE; continue; case 's': *optset |= PCRE_DOTALL; continue; case 'x': *optset |= PCRE_EXTENDED; continue; case 'X': *optset |= PCRE_EXTRA; continue; case 'U': *optset |= PCRE_UNGREEDY; continue; case '-': optset = &unset; continue; case ')': if (brastackptr == 0) { options = (options | set) & (~unset); set = unset = 0; } case ':': if (((set|unset) & PCRE_IMS) != 0) { length += 4; branch_newextra = 2; if (((set|unset) & PCRE_CASELESS) != 0) options |= PCRE_ICHANGED; } goto END_OPTIONS; default: *errorptr = ERR12; goto PCRE_ERROR_RETURN; } } END_OPTIONS: if (c == ')') { if (branch_newextra == 2 && (branch_extra == 0 || branch_extra == 3)) branch_extra += branch_newextra; continue; } } } else { bracount++; if (bracount > EXTRACT_BASIC_MAX) bracket_length += 3; } if (brastackptr >= sizeof(brastack)/sizeof(int)) { *errorptr = ERR19; goto PCRE_ERROR_RETURN; } bralenstack[brastackptr] = branch_extra; branch_extra = branch_newextra; brastack[brastackptr++] = length; length += bracket_length; continue; case ')': length += 3; { int minval = 1; int maxval = 1; int duplength; if (brastackptr > 0) { duplength = length - brastack[--brastackptr]; branch_extra = bralenstack[brastackptr]; } else duplength = 0; if ((c = ptr[1]) == '{' && is_counted_repeat(ptr+2, &compile_block)) { ptr = read_repeat_counts(ptr+2, &minval, &maxval, errorptr, &compile_block); if (*errorptr != NULL) goto PCRE_ERROR_RETURN; } else if (c == '*') { minval = 0; maxval = -1; ptr++; } else if (c == '+') { maxval = -1; ptr++; } else if (c == '?') { minval = 0; ptr++; } if (minval == 0) { length++; if (maxval > 0) length += (maxval - 1) * (duplength + 7); } else { length += (minval - 1) * duplength; if (maxval > minval) length += (maxval - minval) * (duplength + 7) - 6; } } continue; NORMAL_CHAR: default: length += 2; runlength = 0; do { if ((options & PCRE_EXTENDED) != 0) { if ((compile_block.ctypes[c] & ctype_space) != 0) continue; if (c == '#') { while ((c = *(++ptr)) != 0 && c != NEWLINE) ; continue; } } if (c == '\\') { const uschar *saveptr = ptr; c = check_escape(&ptr, errorptr, bracount, options, FALSE, &compile_block); if (*errorptr != NULL) goto PCRE_ERROR_RETURN; if (c < 0) { ptr = saveptr; break; } #ifdef SUPPORT_UTF8 if (c > 127 && (options & PCRE_UTF8) != 0) { int i; for (i = 0; i < sizeof(utf8_table1)/sizeof(int); i++) if (c <= utf8_table1[i]) break; runlength += i; } #endif } runlength++; } while (runlength < MAXLIT && (compile_block.ctypes[c = *(++ptr)] & ctype_meta) == 0); ptr--; length += runlength; continue; } } length += 4; if (length > 65539) { *errorptr = ERR20; return NULL; } size = length + offsetof(real_pcre, code[0]); re = (real_pcre *)(pcre_malloc)(size); if (re == NULL) { *errorptr = ERR21; return NULL; } re->magic_number = MAGIC_NUMBER; re->size = size; re->options = options; re->tables = tables; ptr = (const uschar *)pattern; code = re->code; *code = OP_BRA; bracount = 0; (void)compile_regex(options, -1, &bracount, &code, &ptr, errorptr, FALSE, 0, &reqchar, &countlits, &compile_block); re->top_bracket = bracount; re->top_backref = top_backref; if (*errorptr == NULL && *ptr != 0) *errorptr = ERR22; *code++ = OP_END; #ifndef DEBUG if (code - re->code > length) *errorptr = ERR23; #endif if (top_backref > re->top_bracket) *errorptr = ERR15; if (*errorptr != NULL) { (pcre_free)(re); PCRE_ERROR_RETURN: *erroroffset = ptr - (const uschar *)pattern; return NULL; } if ((options & PCRE_ANCHORED) == 0) { int temp_options = options; if (is_anchored(re->code, &temp_options)) re->options |= PCRE_ANCHORED; else { int ch = find_firstchar(re->code, &temp_options); if (ch >= 0) { re->first_char = ch; re->options |= PCRE_FIRSTSET; } else if (is_startline(re->code)) re->options |= PCRE_STARTLINE; } } if (reqchar >= 0 && (countlits > 1 || (re->options & PCRE_FIRSTSET) == 0)) { re->req_char = reqchar; re->options |= PCRE_REQCHSET; } #ifdef DEBUG printf("Length = %d top_bracket = %d top_backref = %d\n", length, re->top_bracket, re->top_backref); if (re->options != 0) { printf("%s%s%s%s%s%s%s%s%s\n", ((re->options & PCRE_ANCHORED) != 0)? "anchored " : "", ((re->options & PCRE_CASELESS) != 0)? "caseless " : "", ((re->options & PCRE_ICHANGED) != 0)? "case state changed " : "", ((re->options & PCRE_EXTENDED) != 0)? "extended " : "", ((re->options & PCRE_MULTILINE) != 0)? "multiline " : "", ((re->options & PCRE_DOTALL) != 0)? "dotall " : "", ((re->options & PCRE_DOLLAR_ENDONLY) != 0)? "endonly " : "", ((re->options & PCRE_EXTRA) != 0)? "extra " : "", ((re->options & PCRE_UNGREEDY) != 0)? "ungreedy " : ""); } if ((re->options & PCRE_FIRSTSET) != 0) { if (isprint(re->first_char)) printf("First char = %c\n", re->first_char); else printf("First char = \\x%02x\n", re->first_char); } if ((re->options & PCRE_REQCHSET) != 0) { if (isprint(re->req_char)) printf("Req char = %c\n", re->req_char); else printf("Req char = \\x%02x\n", re->req_char); } code_end = code; code_base = code = re->code; while (code < code_end) { int charlength; printf("%3d ", code - code_base); if (*code >= OP_BRA) { if (*code - OP_BRA > EXTRACT_BASIC_MAX) printf("%3d Bra extra", (code[1] << 8) + code[2]); else printf("%3d Bra %d", (code[1] << 8) + code[2], *code - OP_BRA); code += 2; } else switch(*code) { case OP_OPT: printf(" %.2x %s", code[1], OP_names[*code]); code++; break; case OP_CHARS: charlength = *(++code); printf("%3d ", charlength); while (charlength-- > 0) if (isprint(c = *(++code))) printf("%c", c); else printf("\\x%02x", c); break; case OP_KETRMAX: case OP_KETRMIN: case OP_ALT: case OP_KET: case OP_ASSERT: case OP_ASSERT_NOT: case OP_ASSERTBACK: case OP_ASSERTBACK_NOT: case OP_ONCE: case OP_REVERSE: case OP_BRANUMBER: case OP_COND: case OP_CREF: printf("%3d %s", (code[1] << 8) + code[2], OP_names[*code]); code += 2; break; case OP_STAR: case OP_MINSTAR: case OP_PLUS: case OP_MINPLUS: case OP_QUERY: case OP_MINQUERY: case OP_TYPESTAR: case OP_TYPEMINSTAR: case OP_TYPEPLUS: case OP_TYPEMINPLUS: case OP_TYPEQUERY: case OP_TYPEMINQUERY: if (*code >= OP_TYPESTAR) printf(" %s", OP_names[code[1]]); else if (isprint(c = code[1])) printf(" %c", c); else printf(" \\x%02x", c); printf("%s", OP_names[*code++]); break; case OP_EXACT: case OP_UPTO: case OP_MINUPTO: if (isprint(c = code[3])) printf(" %c{", c); else printf(" \\x%02x{", c); if (*code != OP_EXACT) printf("0,"); printf("%d}", (code[1] << 8) + code[2]); if (*code == OP_MINUPTO) printf("?"); code += 3; break; case OP_TYPEEXACT: case OP_TYPEUPTO: case OP_TYPEMINUPTO: printf(" %s{", OP_names[code[3]]); if (*code != OP_TYPEEXACT) printf(","); printf("%d}", (code[1] << 8) + code[2]); if (*code == OP_TYPEMINUPTO) printf("?"); code += 3; break; case OP_NOT: if (isprint(c = *(++code))) printf(" [^%c]", c); else printf(" [^\\x%02x]", c); break; case OP_NOTSTAR: case OP_NOTMINSTAR: case OP_NOTPLUS: case OP_NOTMINPLUS: case OP_NOTQUERY: case OP_NOTMINQUERY: if (isprint(c = code[1])) printf(" [^%c]", c); else printf(" [^\\x%02x]", c); printf("%s", OP_names[*code++]); break; case OP_NOTEXACT: case OP_NOTUPTO: case OP_NOTMINUPTO: if (isprint(c = code[3])) printf(" [^%c]{", c); else printf(" [^\\x%02x]{", c); if (*code != OP_NOTEXACT) printf(","); printf("%d}", (code[1] << 8) + code[2]); if (*code == OP_NOTMINUPTO) printf("?"); code += 3; break; case OP_REF: printf(" \\%d", (code[1] << 8) | code[2]); code += 3; goto CLASS_REF_REPEAT; case OP_CLASS: { int i, min, max; code++; printf(" ["); for (i = 0; i < 256; i++) { if ((code[i/8] & (1 << (i&7))) != 0) { int j; for (j = i+1; j < 256; j++) if ((code[j/8] & (1 << (j&7))) == 0) break; if (i == '-' || i == ']') printf("\\"); if (isprint(i)) printf("%c", i); else printf("\\x%02x", i); if (--j > i) { printf("-"); if (j == '-' || j == ']') printf("\\"); if (isprint(j)) printf("%c", j); else printf("\\x%02x", j); } i = j; } } printf("]"); code += 32; CLASS_REF_REPEAT: switch(*code) { case OP_CRSTAR: case OP_CRMINSTAR: case OP_CRPLUS: case OP_CRMINPLUS: case OP_CRQUERY: case OP_CRMINQUERY: printf("%s", OP_names[*code]); break; case OP_CRRANGE: case OP_CRMINRANGE: min = (code[1] << 8) + code[2]; max = (code[3] << 8) + code[4]; if (max == 0) printf("{%d,}", min); else printf("{%d,%d}", min, max); if (*code == OP_CRMINRANGE) printf("?"); code += 4; break; default: code--; } } break; default: printf(" %s", OP_names[*code]); break; } code++; printf("\n"); } printf("------------------------------------------------------------------\n"); if (code - re->code > length) { *errorptr = ERR23; (pcre_free)(re); *erroroffset = ptr - (uschar *)pattern; return NULL; } #endif return (pcre *)re; }
['pcre *\npcre_compile(const char *pattern, int options, const char **errorptr,\n int *erroroffset, const unsigned char *tables)\n{\nreal_pcre *re;\nint length = 3;\nint runlength;\nint c, reqchar, countlits;\nint bracount = 0;\nint top_backref = 0;\nint branch_extra = 0;\nint branch_newextra;\nunsigned int brastackptr = 0;\nsize_t size;\nuschar *code;\nconst uschar *ptr;\ncompile_data compile_block;\nint brastack[BRASTACK_SIZE];\nuschar bralenstack[BRASTACK_SIZE];\n#ifdef DEBUG\nuschar *code_base, *code_end;\n#endif\n#ifndef SUPPORT_UTF8\nif ((options & PCRE_UTF8) != 0)\n {\n *errorptr = ERR32;\n return NULL;\n }\n#endif\nif (errorptr == NULL) return NULL;\n*errorptr = NULL;\nif (erroroffset == NULL)\n {\n *errorptr = ERR16;\n return NULL;\n }\n*erroroffset = 0;\nif ((options & ~PUBLIC_OPTIONS) != 0)\n {\n *errorptr = ERR17;\n return NULL;\n }\nif (tables == NULL) tables = pcre_default_tables;\ncompile_block.lcc = tables + lcc_offset;\ncompile_block.fcc = tables + fcc_offset;\ncompile_block.cbits = tables + cbits_offset;\ncompile_block.ctypes = tables + ctypes_offset;\nDPRINTF(("------------------------------------------------------------------\\n"));\nDPRINTF(("%s\\n", pattern));\nptr = (const uschar *)(pattern - 1);\nwhile ((c = *(++ptr)) != 0)\n {\n int min, max;\n int class_charcount;\n int bracket_length;\n if ((options & PCRE_EXTENDED) != 0)\n {\n if ((compile_block.ctypes[c] & ctype_space) != 0) continue;\n if (c == \'#\')\n {\n while ((c = *(++ptr)) != 0 && c != NEWLINE) ;\n continue;\n }\n }\n switch(c)\n {\n case \'\\\\\':\n {\n const uschar *save_ptr = ptr;\n c = check_escape(&ptr, errorptr, bracount, options, FALSE, &compile_block);\n if (*errorptr != NULL) goto PCRE_ERROR_RETURN;\n if (c >= 0)\n {\n ptr = save_ptr;\n c = \'\\\\\';\n goto NORMAL_CHAR;\n }\n }\n length++;\n if (c <= -ESC_REF)\n {\n int refnum = -c - ESC_REF;\n if (refnum > top_backref) top_backref = refnum;\n length += 2;\n if (ptr[1] == \'{\' && is_counted_repeat(ptr+2, &compile_block))\n {\n ptr = read_repeat_counts(ptr+2, &min, &max, errorptr, &compile_block);\n if (*errorptr != NULL) goto PCRE_ERROR_RETURN;\n if ((min == 0 && (max == 1 || max == -1)) ||\n (min == 1 && max == -1))\n length++;\n else length += 5;\n if (ptr[1] == \'?\') ptr++;\n }\n }\n continue;\n case \'^\':\n case \'.\':\n case \'$\':\n case \'*\':\n case \'+\':\n case \'?\':\n length++;\n continue;\n case \'{\':\n if (!is_counted_repeat(ptr+1, &compile_block)) goto NORMAL_CHAR;\n ptr = read_repeat_counts(ptr+1, &min, &max, errorptr, &compile_block);\n if (*errorptr != NULL) goto PCRE_ERROR_RETURN;\n if ((min == 0 && (max == 1 || max == -1)) ||\n (min == 1 && max == -1))\n length++;\n else\n {\n length--;\n if (min == 1) length++; else if (min > 0) length += 4;\n if (max > 0) length += 4; else length += 2;\n }\n if (ptr[1] == \'?\') ptr++;\n continue;\n case \'|\':\n length += 3 + branch_extra;\n continue;\n case \'[\':\n class_charcount = 0;\n if (*(++ptr) == \'^\') ptr++;\n do\n {\n if (*ptr == \'\\\\\')\n {\n int ch = check_escape(&ptr, errorptr, bracount, options, TRUE,\n &compile_block);\n if (*errorptr != NULL) goto PCRE_ERROR_RETURN;\n if (-ch == ESC_b) class_charcount++; else class_charcount = 10;\n }\n else class_charcount++;\n ptr++;\n }\n while (*ptr != 0 && *ptr != \']\');\n if (class_charcount == 1) length += 3; else\n {\n length += 33;\n if (*ptr != 0 && ptr[1] == \'{\' && is_counted_repeat(ptr+2, &compile_block))\n {\n ptr = read_repeat_counts(ptr+2, &min, &max, errorptr, &compile_block);\n if (*errorptr != NULL) goto PCRE_ERROR_RETURN;\n if ((min == 0 && (max == 1 || max == -1)) ||\n (min == 1 && max == -1))\n length++;\n else length += 5;\n if (ptr[1] == \'?\') ptr++;\n }\n }\n continue;\n case \'(\':\n branch_newextra = 0;\n bracket_length = 3;\n if (ptr[1] == \'?\')\n {\n int set, unset;\n int *optset;\n switch (c = ptr[2])\n {\n case \'#\':\n ptr += 3;\n while (*ptr != 0 && *ptr != \')\') ptr++;\n if (*ptr == 0)\n {\n *errorptr = ERR18;\n goto PCRE_ERROR_RETURN;\n }\n continue;\n case \':\':\n case \'=\':\n case \'!\':\n case \'>\':\n ptr += 2;\n break;\n case \'R\':\n if (ptr[3] != \')\')\n {\n *errorptr = ERR29;\n goto PCRE_ERROR_RETURN;\n }\n ptr += 3;\n length += 1;\n break;\n case \'<\':\n if (ptr[3] == \'=\' || ptr[3] == \'!\')\n {\n ptr += 3;\n branch_newextra = 3;\n length += 3;\n break;\n }\n *errorptr = ERR24;\n goto PCRE_ERROR_RETURN;\n case \'(\':\n if ((compile_block.ctypes[ptr[3]] & ctype_digit) != 0)\n {\n ptr += 4;\n length += 3;\n while ((compile_block.ctypes[*ptr] & ctype_digit) != 0) ptr++;\n if (*ptr != \')\')\n {\n *errorptr = ERR26;\n goto PCRE_ERROR_RETURN;\n }\n }\n else\n {\n ptr++;\n if (ptr[2] != \'?\' ||\n (ptr[3] != \'=\' && ptr[3] != \'!\' && ptr[3] != \'<\') )\n {\n ptr += 2;\n *errorptr = ERR28;\n goto PCRE_ERROR_RETURN;\n }\n }\n break;\n default:\n set = unset = 0;\n optset = &set;\n ptr += 2;\n for (;; ptr++)\n {\n c = *ptr;\n switch (c)\n {\n case \'i\':\n *optset |= PCRE_CASELESS;\n continue;\n case \'m\':\n *optset |= PCRE_MULTILINE;\n continue;\n case \'s\':\n *optset |= PCRE_DOTALL;\n continue;\n case \'x\':\n *optset |= PCRE_EXTENDED;\n continue;\n case \'X\':\n *optset |= PCRE_EXTRA;\n continue;\n case \'U\':\n *optset |= PCRE_UNGREEDY;\n continue;\n case \'-\':\n optset = &unset;\n continue;\n case \')\':\n if (brastackptr == 0)\n {\n options = (options | set) & (~unset);\n set = unset = 0;\n }\n case \':\':\n if (((set|unset) & PCRE_IMS) != 0)\n {\n length += 4;\n branch_newextra = 2;\n if (((set|unset) & PCRE_CASELESS) != 0) options |= PCRE_ICHANGED;\n }\n goto END_OPTIONS;\n default:\n *errorptr = ERR12;\n goto PCRE_ERROR_RETURN;\n }\n }\n END_OPTIONS:\n if (c == \')\')\n {\n if (branch_newextra == 2 && (branch_extra == 0 || branch_extra == 3))\n branch_extra += branch_newextra;\n continue;\n }\n }\n }\n else\n {\n bracount++;\n if (bracount > EXTRACT_BASIC_MAX) bracket_length += 3;\n }\n if (brastackptr >= sizeof(brastack)/sizeof(int))\n {\n *errorptr = ERR19;\n goto PCRE_ERROR_RETURN;\n }\n bralenstack[brastackptr] = branch_extra;\n branch_extra = branch_newextra;\n brastack[brastackptr++] = length;\n length += bracket_length;\n continue;\n case \')\':\n length += 3;\n {\n int minval = 1;\n int maxval = 1;\n int duplength;\n if (brastackptr > 0)\n {\n duplength = length - brastack[--brastackptr];\n branch_extra = bralenstack[brastackptr];\n }\n else duplength = 0;\n if ((c = ptr[1]) == \'{\' && is_counted_repeat(ptr+2, &compile_block))\n {\n ptr = read_repeat_counts(ptr+2, &minval, &maxval, errorptr,\n &compile_block);\n if (*errorptr != NULL) goto PCRE_ERROR_RETURN;\n }\n else if (c == \'*\') { minval = 0; maxval = -1; ptr++; }\n else if (c == \'+\') { maxval = -1; ptr++; }\n else if (c == \'?\') { minval = 0; ptr++; }\n if (minval == 0)\n {\n length++;\n if (maxval > 0) length += (maxval - 1) * (duplength + 7);\n }\n else\n {\n length += (minval - 1) * duplength;\n if (maxval > minval)\n length += (maxval - minval) * (duplength + 7) - 6;\n }\n }\n continue;\n NORMAL_CHAR:\n default:\n length += 2;\n runlength = 0;\n do\n {\n if ((options & PCRE_EXTENDED) != 0)\n {\n if ((compile_block.ctypes[c] & ctype_space) != 0) continue;\n if (c == \'#\')\n {\n while ((c = *(++ptr)) != 0 && c != NEWLINE) ;\n continue;\n }\n }\n if (c == \'\\\\\')\n {\n const uschar *saveptr = ptr;\n c = check_escape(&ptr, errorptr, bracount, options, FALSE,\n &compile_block);\n if (*errorptr != NULL) goto PCRE_ERROR_RETURN;\n if (c < 0) { ptr = saveptr; break; }\n#ifdef SUPPORT_UTF8\n if (c > 127 && (options & PCRE_UTF8) != 0)\n {\n int i;\n for (i = 0; i < sizeof(utf8_table1)/sizeof(int); i++)\n if (c <= utf8_table1[i]) break;\n runlength += i;\n }\n#endif\n }\n runlength++;\n }\n while (runlength < MAXLIT &&\n (compile_block.ctypes[c = *(++ptr)] & ctype_meta) == 0);\n ptr--;\n length += runlength;\n continue;\n }\n }\nlength += 4;\nif (length > 65539)\n {\n *errorptr = ERR20;\n return NULL;\n }\nsize = length + offsetof(real_pcre, code[0]);\nre = (real_pcre *)(pcre_malloc)(size);\nif (re == NULL)\n {\n *errorptr = ERR21;\n return NULL;\n }\nre->magic_number = MAGIC_NUMBER;\nre->size = size;\nre->options = options;\nre->tables = tables;\nptr = (const uschar *)pattern;\ncode = re->code;\n*code = OP_BRA;\nbracount = 0;\n(void)compile_regex(options, -1, &bracount, &code, &ptr, errorptr, FALSE, 0,\n &reqchar, &countlits, &compile_block);\nre->top_bracket = bracount;\nre->top_backref = top_backref;\nif (*errorptr == NULL && *ptr != 0) *errorptr = ERR22;\n*code++ = OP_END;\n#ifndef DEBUG\nif (code - re->code > length) *errorptr = ERR23;\n#endif\nif (top_backref > re->top_bracket) *errorptr = ERR15;\nif (*errorptr != NULL)\n {\n (pcre_free)(re);\n PCRE_ERROR_RETURN:\n *erroroffset = ptr - (const uschar *)pattern;\n return NULL;\n }\nif ((options & PCRE_ANCHORED) == 0)\n {\n int temp_options = options;\n if (is_anchored(re->code, &temp_options))\n re->options |= PCRE_ANCHORED;\n else\n {\n int ch = find_firstchar(re->code, &temp_options);\n if (ch >= 0)\n {\n re->first_char = ch;\n re->options |= PCRE_FIRSTSET;\n }\n else if (is_startline(re->code))\n re->options |= PCRE_STARTLINE;\n }\n }\nif (reqchar >= 0 && (countlits > 1 || (re->options & PCRE_FIRSTSET) == 0))\n {\n re->req_char = reqchar;\n re->options |= PCRE_REQCHSET;\n }\n#ifdef DEBUG\nprintf("Length = %d top_bracket = %d top_backref = %d\\n",\n length, re->top_bracket, re->top_backref);\nif (re->options != 0)\n {\n printf("%s%s%s%s%s%s%s%s%s\\n",\n ((re->options & PCRE_ANCHORED) != 0)? "anchored " : "",\n ((re->options & PCRE_CASELESS) != 0)? "caseless " : "",\n ((re->options & PCRE_ICHANGED) != 0)? "case state changed " : "",\n ((re->options & PCRE_EXTENDED) != 0)? "extended " : "",\n ((re->options & PCRE_MULTILINE) != 0)? "multiline " : "",\n ((re->options & PCRE_DOTALL) != 0)? "dotall " : "",\n ((re->options & PCRE_DOLLAR_ENDONLY) != 0)? "endonly " : "",\n ((re->options & PCRE_EXTRA) != 0)? "extra " : "",\n ((re->options & PCRE_UNGREEDY) != 0)? "ungreedy " : "");\n }\nif ((re->options & PCRE_FIRSTSET) != 0)\n {\n if (isprint(re->first_char)) printf("First char = %c\\n", re->first_char);\n else printf("First char = \\\\x%02x\\n", re->first_char);\n }\nif ((re->options & PCRE_REQCHSET) != 0)\n {\n if (isprint(re->req_char)) printf("Req char = %c\\n", re->req_char);\n else printf("Req char = \\\\x%02x\\n", re->req_char);\n }\ncode_end = code;\ncode_base = code = re->code;\nwhile (code < code_end)\n {\n int charlength;\n printf("%3d ", code - code_base);\n if (*code >= OP_BRA)\n {\n if (*code - OP_BRA > EXTRACT_BASIC_MAX)\n printf("%3d Bra extra", (code[1] << 8) + code[2]);\n else\n printf("%3d Bra %d", (code[1] << 8) + code[2], *code - OP_BRA);\n code += 2;\n }\n else switch(*code)\n {\n case OP_OPT:\n printf(" %.2x %s", code[1], OP_names[*code]);\n code++;\n break;\n case OP_CHARS:\n charlength = *(++code);\n printf("%3d ", charlength);\n while (charlength-- > 0)\n if (isprint(c = *(++code))) printf("%c", c); else printf("\\\\x%02x", c);\n break;\n case OP_KETRMAX:\n case OP_KETRMIN:\n case OP_ALT:\n case OP_KET:\n case OP_ASSERT:\n case OP_ASSERT_NOT:\n case OP_ASSERTBACK:\n case OP_ASSERTBACK_NOT:\n case OP_ONCE:\n case OP_REVERSE:\n case OP_BRANUMBER:\n case OP_COND:\n case OP_CREF:\n printf("%3d %s", (code[1] << 8) + code[2], OP_names[*code]);\n code += 2;\n break;\n case OP_STAR:\n case OP_MINSTAR:\n case OP_PLUS:\n case OP_MINPLUS:\n case OP_QUERY:\n case OP_MINQUERY:\n case OP_TYPESTAR:\n case OP_TYPEMINSTAR:\n case OP_TYPEPLUS:\n case OP_TYPEMINPLUS:\n case OP_TYPEQUERY:\n case OP_TYPEMINQUERY:\n if (*code >= OP_TYPESTAR)\n printf(" %s", OP_names[code[1]]);\n else if (isprint(c = code[1])) printf(" %c", c);\n else printf(" \\\\x%02x", c);\n printf("%s", OP_names[*code++]);\n break;\n case OP_EXACT:\n case OP_UPTO:\n case OP_MINUPTO:\n if (isprint(c = code[3])) printf(" %c{", c);\n else printf(" \\\\x%02x{", c);\n if (*code != OP_EXACT) printf("0,");\n printf("%d}", (code[1] << 8) + code[2]);\n if (*code == OP_MINUPTO) printf("?");\n code += 3;\n break;\n case OP_TYPEEXACT:\n case OP_TYPEUPTO:\n case OP_TYPEMINUPTO:\n printf(" %s{", OP_names[code[3]]);\n if (*code != OP_TYPEEXACT) printf(",");\n printf("%d}", (code[1] << 8) + code[2]);\n if (*code == OP_TYPEMINUPTO) printf("?");\n code += 3;\n break;\n case OP_NOT:\n if (isprint(c = *(++code))) printf(" [^%c]", c);\n else printf(" [^\\\\x%02x]", c);\n break;\n case OP_NOTSTAR:\n case OP_NOTMINSTAR:\n case OP_NOTPLUS:\n case OP_NOTMINPLUS:\n case OP_NOTQUERY:\n case OP_NOTMINQUERY:\n if (isprint(c = code[1])) printf(" [^%c]", c);\n else printf(" [^\\\\x%02x]", c);\n printf("%s", OP_names[*code++]);\n break;\n case OP_NOTEXACT:\n case OP_NOTUPTO:\n case OP_NOTMINUPTO:\n if (isprint(c = code[3])) printf(" [^%c]{", c);\n else printf(" [^\\\\x%02x]{", c);\n if (*code != OP_NOTEXACT) printf(",");\n printf("%d}", (code[1] << 8) + code[2]);\n if (*code == OP_NOTMINUPTO) printf("?");\n code += 3;\n break;\n case OP_REF:\n printf(" \\\\%d", (code[1] << 8) | code[2]);\n code += 3;\n goto CLASS_REF_REPEAT;\n case OP_CLASS:\n {\n int i, min, max;\n code++;\n printf(" [");\n for (i = 0; i < 256; i++)\n {\n if ((code[i/8] & (1 << (i&7))) != 0)\n {\n int j;\n for (j = i+1; j < 256; j++)\n if ((code[j/8] & (1 << (j&7))) == 0) break;\n if (i == \'-\' || i == \']\') printf("\\\\");\n if (isprint(i)) printf("%c", i); else printf("\\\\x%02x", i);\n if (--j > i)\n {\n printf("-");\n if (j == \'-\' || j == \']\') printf("\\\\");\n if (isprint(j)) printf("%c", j); else printf("\\\\x%02x", j);\n }\n i = j;\n }\n }\n printf("]");\n code += 32;\n CLASS_REF_REPEAT:\n switch(*code)\n {\n case OP_CRSTAR:\n case OP_CRMINSTAR:\n case OP_CRPLUS:\n case OP_CRMINPLUS:\n case OP_CRQUERY:\n case OP_CRMINQUERY:\n printf("%s", OP_names[*code]);\n break;\n case OP_CRRANGE:\n case OP_CRMINRANGE:\n min = (code[1] << 8) + code[2];\n max = (code[3] << 8) + code[4];\n if (max == 0) printf("{%d,}", min);\n else printf("{%d,%d}", min, max);\n if (*code == OP_CRMINRANGE) printf("?");\n code += 4;\n break;\n default:\n code--;\n }\n }\n break;\n default:\n printf(" %s", OP_names[*code]);\n break;\n }\n code++;\n printf("\\n");\n }\nprintf("------------------------------------------------------------------\\n");\nif (code - re->code > length)\n {\n *errorptr = ERR23;\n (pcre_free)(re);\n *erroroffset = ptr - (uschar *)pattern;\n return NULL;\n }\n#endif\nreturn (pcre *)re;\n}']
34,815
0
https://github.com/libav/libav/blob/def5dc1260e99cf7f6e99747013307a152bed801/libavcodec/zmbv.c/#L533
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; ZmbvContext * const c = avctx->priv_data; int zret = Z_OK; int len = buf_size; int hi_ver, lo_ver; if (c->pic.data[0]) avctx->release_buffer(avctx, &c->pic); c->pic.reference = 1; c->pic.buffer_hints = FF_BUFFER_HINTS_VALID; if (avctx->get_buffer(avctx, &c->pic) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; } c->flags = buf[0]; buf++; len--; if (c->flags & ZMBV_KEYFRAME) { hi_ver = buf[0]; lo_ver = buf[1]; c->comp = buf[2]; c->fmt = buf[3]; c->bw = buf[4]; c->bh = buf[5]; buf += 6; len -= 6; av_log(avctx, AV_LOG_DEBUG, "Flags=%X ver=%i.%i comp=%i fmt=%i blk=%ix%i\n", c->flags,hi_ver,lo_ver,c->comp,c->fmt,c->bw,c->bh); if (hi_ver != 0 || lo_ver != 1) { av_log(avctx, AV_LOG_ERROR, "Unsupported version %i.%i\n", hi_ver, lo_ver); return -1; } if (c->bw == 0 || c->bh == 0) { av_log(avctx, AV_LOG_ERROR, "Unsupported block size %ix%i\n", c->bw, c->bh); return -1; } if (c->comp != 0 && c->comp != 1) { av_log(avctx, AV_LOG_ERROR, "Unsupported compression type %i\n", c->comp); return -1; } switch (c->fmt) { case ZMBV_FMT_8BPP: c->bpp = 8; c->decode_intra = zmbv_decode_intra; c->decode_xor = zmbv_decode_xor_8; break; case ZMBV_FMT_15BPP: case ZMBV_FMT_16BPP: c->bpp = 16; c->decode_intra = zmbv_decode_intra; c->decode_xor = zmbv_decode_xor_16; break; #ifdef ZMBV_ENABLE_24BPP case ZMBV_FMT_24BPP: c->bpp = 24; c->decode_intra = zmbv_decode_intra; c->decode_xor = zmbv_decode_xor_24; break; #endif case ZMBV_FMT_32BPP: c->bpp = 32; c->decode_intra = zmbv_decode_intra; c->decode_xor = zmbv_decode_xor_32; break; default: c->decode_intra = NULL; c->decode_xor = NULL; av_log(avctx, AV_LOG_ERROR, "Unsupported (for now) format %i\n", c->fmt); return -1; } zret = inflateReset(&c->zstream); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); return -1; } c->cur = av_realloc(c->cur, avctx->width * avctx->height * (c->bpp / 8)); c->prev = av_realloc(c->prev, avctx->width * avctx->height * (c->bpp / 8)); c->bx = (c->width + c->bw - 1) / c->bw; c->by = (c->height+ c->bh - 1) / c->bh; } if (c->decode_intra == NULL) { av_log(avctx, AV_LOG_ERROR, "Error! Got no format or no keyframe!\n"); return -1; } if (c->comp == 0) { memcpy(c->decomp_buf, buf, len); c->decomp_size = 1; } else { c->zstream.total_in = c->zstream.total_out = 0; c->zstream.next_in = buf; c->zstream.avail_in = len; c->zstream.next_out = c->decomp_buf; c->zstream.avail_out = c->decomp_size; inflate(&c->zstream, Z_FINISH); c->decomp_len = c->zstream.total_out; } if (c->flags & ZMBV_KEYFRAME) { c->pic.key_frame = 1; c->pic.pict_type = AV_PICTURE_TYPE_I; c->decode_intra(c); } else { c->pic.key_frame = 0; c->pic.pict_type = AV_PICTURE_TYPE_P; if (c->decomp_len) c->decode_xor(c); } { uint8_t *out, *src; int i, j; out = c->pic.data[0]; src = c->cur; switch (c->fmt) { case ZMBV_FMT_8BPP: for (j = 0; j < c->height; j++) { for (i = 0; i < c->width; i++) { out[i * 3 + 0] = c->pal[(*src) * 3 + 0]; out[i * 3 + 1] = c->pal[(*src) * 3 + 1]; out[i * 3 + 2] = c->pal[(*src) * 3 + 2]; src++; } out += c->pic.linesize[0]; } break; case ZMBV_FMT_15BPP: for (j = 0; j < c->height; j++) { for (i = 0; i < c->width; i++) { uint16_t tmp = AV_RL16(src); src += 2; out[i * 3 + 0] = (tmp & 0x7C00) >> 7; out[i * 3 + 1] = (tmp & 0x03E0) >> 2; out[i * 3 + 2] = (tmp & 0x001F) << 3; } out += c->pic.linesize[0]; } break; case ZMBV_FMT_16BPP: for (j = 0; j < c->height; j++) { for (i = 0; i < c->width; i++) { uint16_t tmp = AV_RL16(src); src += 2; out[i * 3 + 0] = (tmp & 0xF800) >> 8; out[i * 3 + 1] = (tmp & 0x07E0) >> 3; out[i * 3 + 2] = (tmp & 0x001F) << 3; } out += c->pic.linesize[0]; } break; #ifdef ZMBV_ENABLE_24BPP case ZMBV_FMT_24BPP: for (j = 0; j < c->height; j++) { memcpy(out, src, c->width * 3); src += c->width * 3; out += c->pic.linesize[0]; } break; #endif case ZMBV_FMT_32BPP: for (j = 0; j < c->height; j++) { for (i = 0; i < c->width; i++) { uint32_t tmp = AV_RL32(src); src += 4; AV_WB24(out+(i*3), tmp); } out += c->pic.linesize[0]; } break; default: av_log(avctx, AV_LOG_ERROR, "Cannot handle format %i\n", c->fmt); } FFSWAP(uint8_t *, c->cur, c->prev); } *data_size = sizeof(AVFrame); *(AVFrame*)data = c->pic; return buf_size; }
['static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)\n{\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n ZmbvContext * const c = avctx->priv_data;\n int zret = Z_OK;\n int len = buf_size;\n int hi_ver, lo_ver;\n if (c->pic.data[0])\n avctx->release_buffer(avctx, &c->pic);\n c->pic.reference = 1;\n c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;\n if (avctx->get_buffer(avctx, &c->pic) < 0) {\n av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\\n");\n return -1;\n }\n c->flags = buf[0];\n buf++; len--;\n if (c->flags & ZMBV_KEYFRAME) {\n hi_ver = buf[0];\n lo_ver = buf[1];\n c->comp = buf[2];\n c->fmt = buf[3];\n c->bw = buf[4];\n c->bh = buf[5];\n buf += 6;\n len -= 6;\n av_log(avctx, AV_LOG_DEBUG,\n "Flags=%X ver=%i.%i comp=%i fmt=%i blk=%ix%i\\n",\n c->flags,hi_ver,lo_ver,c->comp,c->fmt,c->bw,c->bh);\n if (hi_ver != 0 || lo_ver != 1) {\n av_log(avctx, AV_LOG_ERROR, "Unsupported version %i.%i\\n",\n hi_ver, lo_ver);\n return -1;\n }\n if (c->bw == 0 || c->bh == 0) {\n av_log(avctx, AV_LOG_ERROR, "Unsupported block size %ix%i\\n",\n c->bw, c->bh);\n return -1;\n }\n if (c->comp != 0 && c->comp != 1) {\n av_log(avctx, AV_LOG_ERROR, "Unsupported compression type %i\\n",\n c->comp);\n return -1;\n }\n switch (c->fmt) {\n case ZMBV_FMT_8BPP:\n c->bpp = 8;\n c->decode_intra = zmbv_decode_intra;\n c->decode_xor = zmbv_decode_xor_8;\n break;\n case ZMBV_FMT_15BPP:\n case ZMBV_FMT_16BPP:\n c->bpp = 16;\n c->decode_intra = zmbv_decode_intra;\n c->decode_xor = zmbv_decode_xor_16;\n break;\n#ifdef ZMBV_ENABLE_24BPP\n case ZMBV_FMT_24BPP:\n c->bpp = 24;\n c->decode_intra = zmbv_decode_intra;\n c->decode_xor = zmbv_decode_xor_24;\n break;\n#endif\n case ZMBV_FMT_32BPP:\n c->bpp = 32;\n c->decode_intra = zmbv_decode_intra;\n c->decode_xor = zmbv_decode_xor_32;\n break;\n default:\n c->decode_intra = NULL;\n c->decode_xor = NULL;\n av_log(avctx, AV_LOG_ERROR,\n "Unsupported (for now) format %i\\n", c->fmt);\n return -1;\n }\n zret = inflateReset(&c->zstream);\n if (zret != Z_OK) {\n av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\\n", zret);\n return -1;\n }\n c->cur = av_realloc(c->cur, avctx->width * avctx->height * (c->bpp / 8));\n c->prev = av_realloc(c->prev, avctx->width * avctx->height * (c->bpp / 8));\n c->bx = (c->width + c->bw - 1) / c->bw;\n c->by = (c->height+ c->bh - 1) / c->bh;\n }\n if (c->decode_intra == NULL) {\n av_log(avctx, AV_LOG_ERROR, "Error! Got no format or no keyframe!\\n");\n return -1;\n }\n if (c->comp == 0) {\n memcpy(c->decomp_buf, buf, len);\n c->decomp_size = 1;\n } else {\n c->zstream.total_in = c->zstream.total_out = 0;\n c->zstream.next_in = buf;\n c->zstream.avail_in = len;\n c->zstream.next_out = c->decomp_buf;\n c->zstream.avail_out = c->decomp_size;\n inflate(&c->zstream, Z_FINISH);\n c->decomp_len = c->zstream.total_out;\n }\n if (c->flags & ZMBV_KEYFRAME) {\n c->pic.key_frame = 1;\n c->pic.pict_type = AV_PICTURE_TYPE_I;\n c->decode_intra(c);\n } else {\n c->pic.key_frame = 0;\n c->pic.pict_type = AV_PICTURE_TYPE_P;\n if (c->decomp_len)\n c->decode_xor(c);\n }\n {\n uint8_t *out, *src;\n int i, j;\n out = c->pic.data[0];\n src = c->cur;\n switch (c->fmt) {\n case ZMBV_FMT_8BPP:\n for (j = 0; j < c->height; j++) {\n for (i = 0; i < c->width; i++) {\n out[i * 3 + 0] = c->pal[(*src) * 3 + 0];\n out[i * 3 + 1] = c->pal[(*src) * 3 + 1];\n out[i * 3 + 2] = c->pal[(*src) * 3 + 2];\n src++;\n }\n out += c->pic.linesize[0];\n }\n break;\n case ZMBV_FMT_15BPP:\n for (j = 0; j < c->height; j++) {\n for (i = 0; i < c->width; i++) {\n uint16_t tmp = AV_RL16(src);\n src += 2;\n out[i * 3 + 0] = (tmp & 0x7C00) >> 7;\n out[i * 3 + 1] = (tmp & 0x03E0) >> 2;\n out[i * 3 + 2] = (tmp & 0x001F) << 3;\n }\n out += c->pic.linesize[0];\n }\n break;\n case ZMBV_FMT_16BPP:\n for (j = 0; j < c->height; j++) {\n for (i = 0; i < c->width; i++) {\n uint16_t tmp = AV_RL16(src);\n src += 2;\n out[i * 3 + 0] = (tmp & 0xF800) >> 8;\n out[i * 3 + 1] = (tmp & 0x07E0) >> 3;\n out[i * 3 + 2] = (tmp & 0x001F) << 3;\n }\n out += c->pic.linesize[0];\n }\n break;\n#ifdef ZMBV_ENABLE_24BPP\n case ZMBV_FMT_24BPP:\n for (j = 0; j < c->height; j++) {\n memcpy(out, src, c->width * 3);\n src += c->width * 3;\n out += c->pic.linesize[0];\n }\n break;\n#endif\n case ZMBV_FMT_32BPP:\n for (j = 0; j < c->height; j++) {\n for (i = 0; i < c->width; i++) {\n uint32_t tmp = AV_RL32(src);\n src += 4;\n AV_WB24(out+(i*3), tmp);\n }\n out += c->pic.linesize[0];\n }\n break;\n default:\n av_log(avctx, AV_LOG_ERROR, "Cannot handle format %i\\n", c->fmt);\n }\n FFSWAP(uint8_t *, c->cur, c->prev);\n }\n *data_size = sizeof(AVFrame);\n *(AVFrame*)data = c->pic;\n return buf_size;\n}']
34,816
0
https://github.com/openssl/openssl/blob/18e1e302452e6dea4500b6f981cee7e151294dea/crypto/bn/bn_ctx.c/#L268
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int ec_GFp_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point,\n BN_CTX *ctx)\n{\n int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *,\n const BIGNUM *, BN_CTX *);\n int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);\n const BIGNUM *p;\n BN_CTX *new_ctx = NULL;\n BIGNUM *rh, *tmp, *Z4, *Z6;\n int ret = -1;\n if (EC_POINT_is_at_infinity(group, point))\n return 1;\n field_mul = group->meth->field_mul;\n field_sqr = group->meth->field_sqr;\n p = group->field;\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return -1;\n }\n BN_CTX_start(ctx);\n rh = BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n Z4 = BN_CTX_get(ctx);\n Z6 = BN_CTX_get(ctx);\n if (Z6 == NULL)\n goto err;\n if (!field_sqr(group, rh, point->X, ctx))\n goto err;\n if (!point->Z_is_one) {\n if (!field_sqr(group, tmp, point->Z, ctx))\n goto err;\n if (!field_sqr(group, Z4, tmp, ctx))\n goto err;\n if (!field_mul(group, Z6, Z4, tmp, ctx))\n goto err;\n if (group->a_is_minus3) {\n if (!BN_mod_lshift1_quick(tmp, Z4, p))\n goto err;\n if (!BN_mod_add_quick(tmp, tmp, Z4, p))\n goto err;\n if (!BN_mod_sub_quick(rh, rh, tmp, p))\n goto err;\n if (!field_mul(group, rh, rh, point->X, ctx))\n goto err;\n } else {\n if (!field_mul(group, tmp, Z4, group->a, ctx))\n goto err;\n if (!BN_mod_add_quick(rh, rh, tmp, p))\n goto err;\n if (!field_mul(group, rh, rh, point->X, ctx))\n goto err;\n }\n if (!field_mul(group, tmp, group->b, Z6, ctx))\n goto err;\n if (!BN_mod_add_quick(rh, rh, tmp, p))\n goto err;\n } else {\n if (!BN_mod_add_quick(rh, rh, group->a, p))\n goto err;\n if (!field_mul(group, rh, rh, point->X, ctx))\n goto err;\n if (!BN_mod_add_quick(rh, rh, group->b, p))\n goto err;\n }\n if (!field_sqr(group, tmp, point->Y, ctx))\n goto err;\n ret = (0 == BN_ucmp(tmp, rh));\n err:\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_start()", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_end()", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
34,817
0
https://github.com/nginx/nginx/blob/29b5a1378460c746a9e9eec7110df31e845b31b2/src/http/modules/ngx_http_referer_module.c/#L533
static char * ngx_http_add_regex_referer(ngx_conf_t *cf, ngx_http_referer_conf_t *rlcf, ngx_str_t *name, ngx_regex_t *regex) { #if (NGX_PCRE) ngx_regex_elt_t *re; ngx_regex_compile_t rc; u_char errstr[NGX_MAX_CONF_ERRSTR]; if (name->len == 1) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "empty regex in \"%V\"", name); return NGX_CONF_ERROR; } if (rlcf->regex == NGX_CONF_UNSET_PTR) { rlcf->regex = ngx_array_create(cf->pool, 2, sizeof(ngx_regex_elt_t)); if (rlcf->regex == NULL) { return NGX_CONF_ERROR; } } re = ngx_array_push(rlcf->regex); if (re == NULL) { return NGX_CONF_ERROR; } if (regex) { re->regex = regex; re->name = name->data; return NGX_CONF_OK; } name->len--; name->data++; ngx_memzero(&rc, sizeof(ngx_regex_compile_t)); rc.pattern = *name; rc.pool = cf->pool; rc.options = NGX_REGEX_CASELESS; rc.err.len = NGX_MAX_CONF_ERRSTR; rc.err.data = errstr; if (ngx_regex_compile(&rc) != NGX_OK) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc.err); return NGX_CONF_ERROR; } re->regex = rc.regex; re->name = name->data; return NGX_CONF_OK; #else ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "the using of the regex \"%V\" requires PCRE library", name); return NGX_CONF_ERROR; #endif }
['static char *\nngx_http_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)\n{\n ngx_http_referer_conf_t *rlcf = conf;\n u_char *p;\n ngx_str_t *value, uri, name;\n ngx_uint_t i, n;\n ngx_http_variable_t *var;\n ngx_http_server_name_t *sn;\n ngx_http_core_srv_conf_t *cscf;\n name.len = sizeof("invalid_referer") - 1;\n name.data = (u_char *) "invalid_referer";\n var = ngx_http_add_variable(cf, &name,\n NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOHASH);\n if (var == NULL) {\n return NGX_CONF_ERROR;\n }\n var->get_handler = ngx_http_referer_variable;\n if (rlcf->keys == NULL) {\n rlcf->keys = ngx_pcalloc(cf->temp_pool, sizeof(ngx_hash_keys_arrays_t));\n if (rlcf->keys == NULL) {\n return NGX_CONF_ERROR;\n }\n rlcf->keys->pool = cf->pool;\n rlcf->keys->temp_pool = cf->pool;\n if (ngx_hash_keys_array_init(rlcf->keys, NGX_HASH_SMALL) != NGX_OK) {\n return NGX_CONF_ERROR;\n }\n }\n value = cf->args->elts;\n for (i = 1; i < cf->args->nelts; i++) {\n if (value[i].len == 0) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "invalid referer \\"%V\\"", &value[i]);\n return NGX_CONF_ERROR;\n }\n if (ngx_strcmp(value[i].data, "none") == 0) {\n rlcf->no_referer = 1;\n continue;\n }\n if (ngx_strcmp(value[i].data, "blocked") == 0) {\n rlcf->blocked_referer = 1;\n continue;\n }\n uri.len = 0;\n uri.data = NULL;\n if (ngx_strcmp(value[i].data, "server_names") == 0) {\n cscf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_core_module);\n sn = cscf->server_names.elts;\n for (n = 0; n < cscf->server_names.nelts; n++) {\n#if (NGX_PCRE)\n if (sn[n].regex) {\n if (ngx_http_add_regex_referer(cf, rlcf, &sn[n].name,\n sn[n].regex->regex)\n != NGX_OK)\n {\n return NGX_CONF_ERROR;\n }\n continue;\n }\n#endif\n if (ngx_http_add_referer(cf, rlcf->keys, &sn[n].name, &uri)\n != NGX_OK)\n {\n return NGX_CONF_ERROR;\n }\n }\n continue;\n }\n if (value[i].data[0] == \'~\') {\n if (ngx_http_add_regex_referer(cf, rlcf, &value[i], NULL) != NGX_OK)\n {\n return NGX_CONF_ERROR;\n }\n continue;\n }\n p = (u_char *) ngx_strchr(value[i].data, \'/\');\n if (p) {\n uri.len = (value[i].data + value[i].len) - p;\n uri.data = p;\n value[i].len = p - value[i].data;\n }\n if (ngx_http_add_referer(cf, rlcf->keys, &value[i], &uri) != NGX_OK) {\n return NGX_CONF_ERROR;\n }\n }\n return NGX_CONF_OK;\n}', 'static char *\nngx_http_add_regex_referer(ngx_conf_t *cf, ngx_http_referer_conf_t *rlcf,\n ngx_str_t *name, ngx_regex_t *regex)\n{\n#if (NGX_PCRE)\n ngx_regex_elt_t *re;\n ngx_regex_compile_t rc;\n u_char errstr[NGX_MAX_CONF_ERRSTR];\n if (name->len == 1) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "empty regex in \\"%V\\"", name);\n return NGX_CONF_ERROR;\n }\n if (rlcf->regex == NGX_CONF_UNSET_PTR) {\n rlcf->regex = ngx_array_create(cf->pool, 2, sizeof(ngx_regex_elt_t));\n if (rlcf->regex == NULL) {\n return NGX_CONF_ERROR;\n }\n }\n re = ngx_array_push(rlcf->regex);\n if (re == NULL) {\n return NGX_CONF_ERROR;\n }\n if (regex) {\n re->regex = regex;\n re->name = name->data;\n return NGX_CONF_OK;\n }\n name->len--;\n name->data++;\n ngx_memzero(&rc, sizeof(ngx_regex_compile_t));\n rc.pattern = *name;\n rc.pool = cf->pool;\n rc.options = NGX_REGEX_CASELESS;\n rc.err.len = NGX_MAX_CONF_ERRSTR;\n rc.err.data = errstr;\n if (ngx_regex_compile(&rc) != NGX_OK) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc.err);\n return NGX_CONF_ERROR;\n }\n re->regex = rc.regex;\n re->name = name->data;\n return NGX_CONF_OK;\n#else\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "the using of the regex \\"%V\\" requires PCRE library",\n name);\n return NGX_CONF_ERROR;\n#endif\n}']
34,818
0
https://github.com/libav/libav/blob/953302656aaaeb1bc737b59fae2d5a11b75d9f7d/libavcodec/simple_idct.c/#L103
static inline void idctRowCondDC (DCTELEM * row) { int a0, a1, a2, a3, b0, b1, b2, b3; #if HAVE_FAST_64BIT #define ROW0_MASK (0xffffLL << 48 * HAVE_BIGENDIAN) if (((((uint64_t *)row)[0] & ~ROW0_MASK) | ((uint64_t *)row)[1]) == 0) { uint64_t temp = (row[0] << 3) & 0xffff; temp += temp << 16; temp += temp << 32; ((uint64_t *)row)[0] = temp; ((uint64_t *)row)[1] = temp; return; } #else if (!(((uint32_t*)row)[1] | ((uint32_t*)row)[2] | ((uint32_t*)row)[3] | row[1])) { uint32_t temp = (row[0] << 3) & 0xffff; temp += temp << 16; ((uint32_t*)row)[0]=((uint32_t*)row)[1] = ((uint32_t*)row)[2]=((uint32_t*)row)[3] = temp; return; } #endif a0 = (W4 * row[0]) + (1 << (ROW_SHIFT - 1)); a1 = a0; a2 = a0; a3 = a0; a0 += W2 * row[2]; a1 += W6 * row[2]; a2 -= W6 * row[2]; a3 -= W2 * row[2]; b0 = MUL16(W1, row[1]); MAC16(b0, W3, row[3]); b1 = MUL16(W3, row[1]); MAC16(b1, -W7, row[3]); b2 = MUL16(W5, row[1]); MAC16(b2, -W1, row[3]); b3 = MUL16(W7, row[1]); MAC16(b3, -W5, row[3]); if (AV_RN64A(row + 4)) { a0 += W4*row[4] + W6*row[6]; a1 += - W4*row[4] - W2*row[6]; a2 += - W4*row[4] + W2*row[6]; a3 += W4*row[4] - W6*row[6]; MAC16(b0, W5, row[5]); MAC16(b0, W7, row[7]); MAC16(b1, -W1, row[5]); MAC16(b1, -W5, row[7]); MAC16(b2, W7, row[5]); MAC16(b2, W3, row[7]); MAC16(b3, W3, row[5]); MAC16(b3, -W1, row[7]); } row[0] = (a0 + b0) >> ROW_SHIFT; row[7] = (a0 - b0) >> ROW_SHIFT; row[1] = (a1 + b1) >> ROW_SHIFT; row[6] = (a1 - b1) >> ROW_SHIFT; row[2] = (a2 + b2) >> ROW_SHIFT; row[5] = (a2 - b2) >> ROW_SHIFT; row[3] = (a3 + b3) >> ROW_SHIFT; row[4] = (a3 - b3) >> ROW_SHIFT; }
['void ff_wmv2_add_mb(MpegEncContext *s, DCTELEM block1[6][64], uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr){\n Wmv2Context * const w= (Wmv2Context*)s;\n wmv2_add_block(w, block1[0], dest_y , s->linesize, 0);\n wmv2_add_block(w, block1[1], dest_y + 8 , s->linesize, 1);\n wmv2_add_block(w, block1[2], dest_y + 8*s->linesize, s->linesize, 2);\n wmv2_add_block(w, block1[3], dest_y + 8 + 8*s->linesize, s->linesize, 3);\n if(s->flags&CODEC_FLAG_GRAY) return;\n wmv2_add_block(w, block1[4], dest_cb , s->uvlinesize, 4);\n wmv2_add_block(w, block1[5], dest_cr , s->uvlinesize, 5);\n}', 'static void wmv2_add_block(Wmv2Context *w, DCTELEM *block1, uint8_t *dst, int stride, int n){\n MpegEncContext * const s= &w->s;\n if (s->block_last_index[n] >= 0) {\n switch(w->abt_type_table[n]){\n case 0:\n s->dsp.idct_add (dst, stride, block1);\n break;\n case 1:\n ff_simple_idct84_add(dst , stride, block1);\n ff_simple_idct84_add(dst + 4*stride, stride, w->abt_block2[n]);\n s->dsp.clear_block(w->abt_block2[n]);\n break;\n case 2:\n ff_simple_idct48_add(dst , stride, block1);\n ff_simple_idct48_add(dst + 4 , stride, w->abt_block2[n]);\n s->dsp.clear_block(w->abt_block2[n]);\n break;\n default:\n av_log(s->avctx, AV_LOG_ERROR, "internal error in WMV2 abt\\n");\n }\n }\n}', 'void ff_simple_idct84_add(uint8_t *dest, int line_size, DCTELEM *block)\n{\n int i;\n for(i=0; i<4; i++) {\n idctRowCondDC(block + i*8);\n }\n for(i=0;i<8;i++) {\n idct4col_add(dest + i, line_size, block + i);\n }\n}', 'static inline void idctRowCondDC (DCTELEM * row)\n{\n int a0, a1, a2, a3, b0, b1, b2, b3;\n#if HAVE_FAST_64BIT\n#define ROW0_MASK (0xffffLL << 48 * HAVE_BIGENDIAN)\n if (((((uint64_t *)row)[0] & ~ROW0_MASK) | ((uint64_t *)row)[1]) == 0) {\n uint64_t temp = (row[0] << 3) & 0xffff;\n temp += temp << 16;\n temp += temp << 32;\n ((uint64_t *)row)[0] = temp;\n ((uint64_t *)row)[1] = temp;\n return;\n }\n#else\n if (!(((uint32_t*)row)[1] |\n ((uint32_t*)row)[2] |\n ((uint32_t*)row)[3] |\n row[1])) {\n uint32_t temp = (row[0] << 3) & 0xffff;\n temp += temp << 16;\n ((uint32_t*)row)[0]=((uint32_t*)row)[1] =\n ((uint32_t*)row)[2]=((uint32_t*)row)[3] = temp;\n return;\n }\n#endif\n a0 = (W4 * row[0]) + (1 << (ROW_SHIFT - 1));\n a1 = a0;\n a2 = a0;\n a3 = a0;\n a0 += W2 * row[2];\n a1 += W6 * row[2];\n a2 -= W6 * row[2];\n a3 -= W2 * row[2];\n b0 = MUL16(W1, row[1]);\n MAC16(b0, W3, row[3]);\n b1 = MUL16(W3, row[1]);\n MAC16(b1, -W7, row[3]);\n b2 = MUL16(W5, row[1]);\n MAC16(b2, -W1, row[3]);\n b3 = MUL16(W7, row[1]);\n MAC16(b3, -W5, row[3]);\n if (AV_RN64A(row + 4)) {\n a0 += W4*row[4] + W6*row[6];\n a1 += - W4*row[4] - W2*row[6];\n a2 += - W4*row[4] + W2*row[6];\n a3 += W4*row[4] - W6*row[6];\n MAC16(b0, W5, row[5]);\n MAC16(b0, W7, row[7]);\n MAC16(b1, -W1, row[5]);\n MAC16(b1, -W5, row[7]);\n MAC16(b2, W7, row[5]);\n MAC16(b2, W3, row[7]);\n MAC16(b3, W3, row[5]);\n MAC16(b3, -W1, row[7]);\n }\n row[0] = (a0 + b0) >> ROW_SHIFT;\n row[7] = (a0 - b0) >> ROW_SHIFT;\n row[1] = (a1 + b1) >> ROW_SHIFT;\n row[6] = (a1 - b1) >> ROW_SHIFT;\n row[2] = (a2 + b2) >> ROW_SHIFT;\n row[5] = (a2 - b2) >> ROW_SHIFT;\n row[3] = (a3 + b3) >> ROW_SHIFT;\n row[4] = (a3 - b3) >> ROW_SHIFT;\n}']
34,819
0
https://gitlab.com/libtiff/libtiff/blob/709e93ded0000128625a23838756a408ea30745d/libtiff/tif_read.c/#L948
static int TIFFStartTile(TIFF* tif, uint32 tile) { TIFFDirectory *td = &tif->tif_dir; if ((tif->tif_flags & TIFF_CODERSETUP) == 0) { if (!(*tif->tif_setupdecode)(tif)) return (0); tif->tif_flags |= TIFF_CODERSETUP; } tif->tif_curtile = tile; tif->tif_row = (tile % TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth)) * td->td_tilelength; tif->tif_col = (tile % TIFFhowmany_32(td->td_imagelength, td->td_tilelength)) * td->td_tilewidth; tif->tif_flags &= ~TIFF_BUF4WRITE; if (tif->tif_flags&TIFF_NOREADRAW) { tif->tif_rawcp = NULL; tif->tif_rawcc = 0; } else { tif->tif_rawcp = tif->tif_rawdata; tif->tif_rawcc = (tmsize_t)td->td_stripbytecount[tile]; } return ((*tif->tif_predecode)(tif, (uint16)(tile/td->td_stripsperimage))); }
['tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_t tile){\n\tuint16 edge=0;\n\ttsize_t written=0;\n\tunsigned char* buffer=NULL;\n\ttsize_t bufferoffset=0;\n\tunsigned char* samplebuffer=NULL;\n\ttsize_t samplebufferoffset=0;\n\ttsize_t read=0;\n\tuint16 i=0;\n\tttile_t tilecount=0;\n\ttsize_t tilesize=0;\n\tttile_t septilecount=0;\n\ttsize_t septilesize=0;\n#ifdef JPEG_SUPPORT\n\tunsigned char* jpt;\n\tfloat* xfloatp;\n\tuint32 xuint32=0;\n#endif\n\tedge |= t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile);\n\tedge |= t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile);\n\tif( (t2p->pdf_transcode == T2P_TRANSCODE_RAW) && ((edge == 0)\n#if defined(JPEG_SUPPORT) || defined(OJPEG_SUPPORT)\n\t\t|| (t2p->pdf_compression == T2P_COMPRESS_JPEG)\n#endif\n\t)\n\t){\n#ifdef CCITT_SUPPORT\n\t\tif(t2p->pdf_compression == T2P_COMPRESS_G4){\n\t\t\tbuffer= (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tTIFFReadRawTile(input, tile, (tdata_t) buffer, t2p->tiff_datasize);\n\t\t\tif (t2p->tiff_fillorder==FILLORDER_LSB2MSB){\n\t\t\t\t\tTIFFReverseBits(buffer, t2p->tiff_datasize);\n\t\t\t}\n\t\t\tt2pWriteFile(output, (tdata_t) buffer, t2p->tiff_datasize);\n\t\t\t_TIFFfree(buffer);\n\t\t\treturn(t2p->tiff_datasize);\n\t\t}\n#endif\n#ifdef ZIP_SUPPORT\n\t\tif(t2p->pdf_compression == T2P_COMPRESS_ZIP){\n\t\t\tbuffer= (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tTIFFReadRawTile(input, tile, (tdata_t) buffer, t2p->tiff_datasize);\n\t\t\tif (t2p->tiff_fillorder==FILLORDER_LSB2MSB){\n\t\t\t\t\tTIFFReverseBits(buffer, t2p->tiff_datasize);\n\t\t\t}\n\t\t\tt2pWriteFile(output, (tdata_t) buffer, t2p->tiff_datasize);\n\t\t\t_TIFFfree(buffer);\n\t\t\treturn(t2p->tiff_datasize);\n\t\t}\n#endif\n#ifdef OJPEG_SUPPORT\n\t\tif(t2p->tiff_compression == COMPRESSION_OJPEG){\n\t\t\tif(! t2p->pdf_ojpegdata){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"No support for OJPEG image %s with "\n "bad tables",\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tbuffer=(unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\t_TIFFmemcpy(buffer, t2p->pdf_ojpegdata, t2p->pdf_ojpegdatalength);\n\t\t\tif(edge!=0){\n\t\t\t\tif(t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile)){\n\t\t\t\t\tbuffer[7]=\n\t\t\t\t\t\t(t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength >> 8) & 0xff;\n\t\t\t\t\tbuffer[8]=\n\t\t\t\t\t\t(t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength ) & 0xff;\n\t\t\t\t}\n\t\t\t\tif(t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile)){\n\t\t\t\t\tbuffer[9]=\n\t\t\t\t\t\t(t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth >> 8) & 0xff;\n\t\t\t\t\tbuffer[10]=\n\t\t\t\t\t\t(t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth ) & 0xff;\n\t\t\t\t}\n\t\t\t}\n\t\t\tbufferoffset=t2p->pdf_ojpegdatalength;\n\t\t\tbufferoffset+=TIFFReadRawTile(input,\n\t\t\t\t\ttile,\n\t\t\t\t\t(tdata_t) &(((unsigned char*)buffer)[bufferoffset]),\n\t\t\t\t\t-1);\n\t\t\t((unsigned char*)buffer)[bufferoffset++]=0xff;\n\t\t\t((unsigned char*)buffer)[bufferoffset++]=0xd9;\n\t\t\tt2pWriteFile(output, (tdata_t) buffer, bufferoffset);\n\t\t\t_TIFFfree(buffer);\n\t\t\treturn(bufferoffset);\n\t\t}\n#endif\n#ifdef JPEG_SUPPORT\n\t\tif(t2p->tiff_compression == COMPRESSION_JPEG){\n\t\t\tunsigned char table_end[2];\n\t\t\tuint32 count = 0;\n\t\t\tbuffer= (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\tt2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tif(TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt) != 0) {\n\t\t\t\tif (count > 0) {\n\t\t\t\t\t_TIFFmemcpy(buffer, jpt, count);\n\t\t\t\t\tbufferoffset += count - 2;\n\t\t\t\t\ttable_end[0] = buffer[bufferoffset-2];\n\t\t\t\t\ttable_end[1] = buffer[bufferoffset-1];\n\t\t\t\t}\n\t\t\t\tif (count > 0) {\n\t\t\t\t\txuint32 = bufferoffset;\n\t\t\t\t\tbufferoffset += TIFFReadRawTile(\n\t\t\t\t\t\tinput,\n\t\t\t\t\t\ttile,\n\t\t\t\t\t\t(tdata_t) &(((unsigned char*)buffer)[bufferoffset-2]),\n\t\t\t\t\t\t-1);\n\t\t\t\t\t\tbuffer[xuint32-2]=table_end[0];\n\t\t\t\t\t\tbuffer[xuint32-1]=table_end[1];\n\t\t\t\t} else {\n\t\t\t\t\tbufferoffset += TIFFReadRawTile(\n\t\t\t\t\t\tinput,\n\t\t\t\t\t\ttile,\n\t\t\t\t\t\t(tdata_t) &(((unsigned char*)buffer)[bufferoffset]),\n\t\t\t\t\t\t-1);\n\t\t\t\t}\n\t\t\t}\n\t\t\tt2pWriteFile(output, (tdata_t) buffer, bufferoffset);\n\t\t\t_TIFFfree(buffer);\n\t\t\treturn(bufferoffset);\n\t\t}\n#endif\n\t\t(void)0;\n\t}\n\tif(t2p->pdf_sample==T2P_SAMPLE_NOTHING){\n\t\tbuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\tif(buffer==NULL){\n\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t"Can\'t allocate %lu bytes of memory for "\n "t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\tTIFFFileName(input));\n\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\treturn(0);\n\t\t}\n\t\tread = TIFFReadEncodedTile(\n\t\t\tinput,\n\t\t\ttile,\n\t\t\t(tdata_t) &buffer[bufferoffset],\n\t\t\tt2p->tiff_datasize);\n\t\tif(read==-1){\n\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t"Error on decoding tile %u of %s",\n\t\t\t\ttile,\n\t\t\t\tTIFFFileName(input));\n\t\t\t_TIFFfree(buffer);\n\t\t\tt2p->t2p_error=T2P_ERR_ERROR;\n\t\t\treturn(0);\n\t\t}\n\t} else {\n\t\tif(t2p->pdf_sample == T2P_SAMPLE_PLANAR_SEPARATE_TO_CONTIG){\n\t\t\tseptilesize=TIFFTileSize(input);\n\t\t\tseptilecount=TIFFNumberOfTiles(input);\n\t\t\ttilesize=septilesize*t2p->tiff_samplesperpixel;\n\t\t\ttilecount=septilecount/t2p->tiff_samplesperpixel;\n\t\t\tbuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tsamplebuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(samplebuffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tsamplebufferoffset=0;\n\t\t\tfor(i=0;i<t2p->tiff_samplesperpixel;i++){\n\t\t\t\tread =\n\t\t\t\t\tTIFFReadEncodedTile(input,\n\t\t\t\t\t\ttile + i*tilecount,\n\t\t\t\t\t\t(tdata_t) &(samplebuffer[samplebufferoffset]),\n\t\t\t\t\t\tseptilesize);\n\t\t\t\tif(read==-1){\n\t\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t\t"Error on decoding tile %u of %s",\n\t\t\t\t\t\ttile + i*tilecount,\n\t\t\t\t\t\tTIFFFileName(input));\n\t\t\t\t\t\t_TIFFfree(samplebuffer);\n\t\t\t\t\t\t_TIFFfree(buffer);\n\t\t\t\t\tt2p->t2p_error=T2P_ERR_ERROR;\n\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t\tsamplebufferoffset+=read;\n\t\t\t}\n\t\t\tt2p_sample_planar_separate_to_contig(\n\t\t\t\tt2p,\n\t\t\t\t&(buffer[bufferoffset]),\n\t\t\t\tsamplebuffer,\n\t\t\t\tsamplebufferoffset);\n\t\t\tbufferoffset+=samplebufferoffset;\n\t\t\t_TIFFfree(samplebuffer);\n\t\t}\n\t\tif(buffer==NULL){\n\t\t\tbuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tread = TIFFReadEncodedTile(\n\t\t\t\tinput,\n\t\t\t\ttile,\n\t\t\t\t(tdata_t) &buffer[bufferoffset],\n\t\t\t\tt2p->tiff_datasize);\n\t\t\tif(read==-1){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Error on decoding tile %u of %s",\n\t\t\t\t\ttile,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\t_TIFFfree(buffer);\n\t\t\t\tt2p->t2p_error=T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t}\n\t\tif(t2p->pdf_sample & T2P_SAMPLE_RGBA_TO_RGB){\n\t\t\tt2p->tiff_datasize=t2p_sample_rgba_to_rgb(\n\t\t\t\t(tdata_t)buffer,\n\t\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth\n\t\t\t\t*t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t\t}\n\t\tif(t2p->pdf_sample & T2P_SAMPLE_RGBAA_TO_RGB){\n\t\t\tt2p->tiff_datasize=t2p_sample_rgbaa_to_rgb(\n\t\t\t\t(tdata_t)buffer,\n\t\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth\n\t\t\t\t*t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t\t}\n\t\tif(t2p->pdf_sample & T2P_SAMPLE_YCBCR_TO_RGB){\n\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t"No support for YCbCr to RGB in tile for %s",\n\t\t\t\tTIFFFileName(input));\n\t\t\t_TIFFfree(buffer);\n\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\treturn(0);\n\t\t}\n\t\tif(t2p->pdf_sample & T2P_SAMPLE_LAB_SIGNED_TO_UNSIGNED){\n\t\t\tt2p->tiff_datasize=t2p_sample_lab_signed_to_unsigned(\n\t\t\t\t(tdata_t)buffer,\n\t\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth\n\t\t\t\t*t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t\t}\n\t}\n\tif(t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile) != 0){\n\t\tt2p_tile_collapse_left(\n\t\t\tbuffer,\n\t\t\tTIFFTileRowSize(input),\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t}\n\tt2p_disable(output);\n\tTIFFSetField(output, TIFFTAG_PHOTOMETRIC, t2p->tiff_photometric);\n\tTIFFSetField(output, TIFFTAG_BITSPERSAMPLE, t2p->tiff_bitspersample);\n\tTIFFSetField(output, TIFFTAG_SAMPLESPERPIXEL, t2p->tiff_samplesperpixel);\n\tif(t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile) == 0){\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_IMAGEWIDTH,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth);\n\t} else {\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_IMAGEWIDTH,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth);\n\t}\n\tif(t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile) == 0){\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_IMAGELENGTH,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_ROWSPERSTRIP,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t} else {\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_IMAGELENGTH,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength);\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_ROWSPERSTRIP,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength);\n\t}\n\tTIFFSetField(output, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);\n\tTIFFSetField(output, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);\n\tswitch(t2p->pdf_compression){\n\tcase T2P_COMPRESS_NONE:\n\t\tTIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_NONE);\n\t\tbreak;\n#ifdef CCITT_SUPPORT\n\tcase T2P_COMPRESS_G4:\n\t\tTIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4);\n\t\tbreak;\n#endif\n#ifdef JPEG_SUPPORT\n\tcase T2P_COMPRESS_JPEG:\n\t\tif (t2p->tiff_photometric==PHOTOMETRIC_YCBCR) {\n\t\t\tuint16 hor = 0, ver = 0;\n\t\t\tif (TIFFGetField(input, TIFFTAG_YCBCRSUBSAMPLING, &hor, &ver)!=0) {\n\t\t\t\tif (hor != 0 && ver != 0) {\n\t\t\t\t\tTIFFSetField(output, TIFFTAG_YCBCRSUBSAMPLING, hor, ver);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(TIFFGetField(input, TIFFTAG_REFERENCEBLACKWHITE, &xfloatp)!=0){\n\t\t\t\tTIFFSetField(output, TIFFTAG_REFERENCEBLACKWHITE, xfloatp);\n\t\t\t}\n\t\t}\n\t\tTIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_JPEG);\n\t\tTIFFSetField(output, TIFFTAG_JPEGTABLESMODE, 0);\n\t\tif(t2p->pdf_colorspace & (T2P_CS_RGB | T2P_CS_LAB)){\n\t\t\tTIFFSetField(output, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_YCBCR);\n\t\t\tif(t2p->tiff_photometric != PHOTOMETRIC_YCBCR){\n\t\t\t\tTIFFSetField(output, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);\n\t\t\t} else {\n\t\t\t\tTIFFSetField(output, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RAW);\n\t\t\t}\n\t\t}\n\t\tif(t2p->pdf_colorspace & T2P_CS_GRAY){\n\t\t\t(void)0;\n\t\t}\n\t\tif(t2p->pdf_colorspace & T2P_CS_CMYK){\n\t\t\t(void)0;\n\t\t}\n\t\tif(t2p->pdf_defaultcompressionquality != 0){\n\t\t\tTIFFSetField(output,\n\t\t\t\tTIFFTAG_JPEGQUALITY,\n\t\t\t\tt2p->pdf_defaultcompressionquality);\n\t\t}\n\t\tbreak;\n#endif\n#ifdef ZIP_SUPPORT\n\tcase T2P_COMPRESS_ZIP:\n\t\tTIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);\n\t\tif(t2p->pdf_defaultcompressionquality%100 != 0){\n\t\t\tTIFFSetField(output,\n\t\t\t\tTIFFTAG_PREDICTOR,\n\t\t\t\tt2p->pdf_defaultcompressionquality % 100);\n\t\t}\n\t\tif(t2p->pdf_defaultcompressionquality/100 != 0){\n\t\t\tTIFFSetField(output,\n\t\t\t\tTIFFTAG_ZIPQUALITY,\n\t\t\t\t(t2p->pdf_defaultcompressionquality / 100));\n\t\t}\n\t\tbreak;\n#endif\n\tdefault:\n\t\tbreak;\n\t}\n\tt2p_enable(output);\n\tt2p->outputwritten = 0;\n\tbufferoffset = TIFFWriteEncodedStrip(output, (tstrip_t) 0, buffer,\n\t\t\t\t\t TIFFStripSize(output));\n\tif (buffer != NULL) {\n\t\t_TIFFfree(buffer);\n\t\tbuffer = NULL;\n\t}\n\tif (bufferoffset == -1) {\n\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t "Error writing encoded tile to output PDF %s",\n\t\t\t TIFFFileName(output));\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\treturn(0);\n\t}\n\twritten = t2p->outputwritten;\n\treturn(written);\n}', 'tmsize_t\nTIFFReadEncodedTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size)\n{\n\tstatic const char module[] = "TIFFReadEncodedTile";\n\tTIFFDirectory *td = &tif->tif_dir;\n\ttmsize_t tilesize = tif->tif_tilesize;\n\tif (!TIFFCheckRead(tif, 1))\n\t\treturn ((tmsize_t)(-1));\n\tif (tile >= td->td_nstrips) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t "%lu: Tile out of range, max %lu",\n\t\t (unsigned long) tile, (unsigned long) td->td_nstrips);\n\t\treturn ((tmsize_t)(-1));\n\t}\n\tif (size == (tmsize_t)(-1))\n\t\tsize = tilesize;\n\telse if (size > tilesize)\n\t\tsize = tilesize;\n\tif (TIFFFillTile(tif, tile) && (*tif->tif_decodetile)(tif,\n\t (uint8*) buf, size, (uint16)(tile/td->td_stripsperimage))) {\n\t\t(*tif->tif_postdecode)(tif, (uint8*) buf, size);\n\t\treturn (size);\n\t} else\n\t\treturn ((tmsize_t)(-1));\n}', 'int\nTIFFFillTile(TIFF* tif, uint32 tile)\n{\n\tstatic const char module[] = "TIFFFillTile";\n\tTIFFDirectory *td = &tif->tif_dir;\n\tif ((tif->tif_flags&TIFF_NOREADRAW)==0)\n\t{\n\t\tuint64 bytecount = td->td_stripbytecount[tile];\n\t\tif (bytecount <= 0) {\n#if defined(__WIN32__) && defined(_MSC_VER)\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t"%I64u: Invalid tile byte count, tile %lu",\n\t\t\t\t (unsigned __int64) bytecount,\n\t\t\t\t (unsigned long) tile);\n#else\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t"%llu: Invalid tile byte count, tile %lu",\n\t\t\t\t (unsigned long long) bytecount,\n\t\t\t\t (unsigned long) tile);\n#endif\n\t\t\treturn (0);\n\t\t}\n\t\tif (isMapped(tif) &&\n\t\t (isFillOrder(tif, td->td_fillorder)\n\t\t || (tif->tif_flags & TIFF_NOBITREV))) {\n\t\t\tif ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)\n\t\t\t\t_TIFFfree(tif->tif_rawdata);\n\t\t\ttif->tif_flags &= ~TIFF_MYBUFFER;\n\t\t\tif (bytecount > (uint64)tif->tif_size ||\n\t\t\t td->td_stripoffset[tile] > (uint64)tif->tif_size - bytecount) {\n\t\t\t\ttif->tif_curtile = NOTILE;\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t\ttif->tif_rawdatasize = (tmsize_t)bytecount;\n\t\t\ttif->tif_rawdata =\n\t\t\t\ttif->tif_base + (tmsize_t)td->td_stripoffset[tile];\n tif->tif_rawdataoff = 0;\n tif->tif_rawdataloaded = (tmsize_t) bytecount;\n\t\t} else {\n\t\t\ttmsize_t bytecountm;\n\t\t\tbytecountm=(tmsize_t)bytecount;\n\t\t\tif ((uint64)bytecountm!=bytecount)\n\t\t\t{\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tif (bytecountm > tif->tif_rawdatasize) {\n\t\t\t\ttif->tif_curtile = NOTILE;\n\t\t\t\tif ((tif->tif_flags & TIFF_MYBUFFER) == 0) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Data buffer too small to hold tile %lu",\n\t\t\t\t\t (unsigned long) tile);\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (!TIFFReadBufferSetup(tif, 0, bytecountm))\n\t\t\t\t\treturn (0);\n\t\t\t}\n\t\t\tif (TIFFReadRawTile1(tif, tile, tif->tif_rawdata,\n\t\t\t bytecountm, module) != bytecountm)\n\t\t\t\treturn (0);\n tif->tif_rawdataoff = 0;\n tif->tif_rawdataloaded = bytecountm;\n\t\t\tif (!isFillOrder(tif, td->td_fillorder) &&\n\t\t\t (tif->tif_flags & TIFF_NOBITREV) == 0)\n\t\t\t\tTIFFReverseBits(tif->tif_rawdata,\n tif->tif_rawdataloaded);\n\t\t}\n\t}\n\treturn (TIFFStartTile(tif, tile));\n}', 'static int\nTIFFStartTile(TIFF* tif, uint32 tile)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tif ((tif->tif_flags & TIFF_CODERSETUP) == 0) {\n\t\tif (!(*tif->tif_setupdecode)(tif))\n\t\t\treturn (0);\n\t\ttif->tif_flags |= TIFF_CODERSETUP;\n\t}\n\ttif->tif_curtile = tile;\n\ttif->tif_row =\n\t (tile % TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth)) *\n\t\ttd->td_tilelength;\n\ttif->tif_col =\n\t (tile % TIFFhowmany_32(td->td_imagelength, td->td_tilelength)) *\n\t\ttd->td_tilewidth;\n tif->tif_flags &= ~TIFF_BUF4WRITE;\n\tif (tif->tif_flags&TIFF_NOREADRAW)\n\t{\n\t\ttif->tif_rawcp = NULL;\n\t\ttif->tif_rawcc = 0;\n\t}\n\telse\n\t{\n\t\ttif->tif_rawcp = tif->tif_rawdata;\n\t\ttif->tif_rawcc = (tmsize_t)td->td_stripbytecount[tile];\n\t}\n\treturn ((*tif->tif_predecode)(tif,\n\t\t\t(uint16)(tile/td->td_stripsperimage)));\n}']
34,820
0
https://github.com/openssl/openssl/blob/e1cfd184dafb3e0759c567d7ca13a92b5491ff89/test/evp_test.c/#L1773
static int encode_test_init(EVP_TEST *t, const char *encoding) { ENCODE_DATA *edata = OPENSSL_zalloc(sizeof(*edata)); if (strcmp(encoding, "canonical") == 0) { edata->encoding = BASE64_CANONICAL_ENCODING; } else if (strcmp(encoding, "valid") == 0) { edata->encoding = BASE64_VALID_ENCODING; } else if (strcmp(encoding, "invalid") == 0) { edata->encoding = BASE64_INVALID_ENCODING; t->expected_err = OPENSSL_strdup("DECODE_ERROR"); if (t->expected_err == NULL) return 0; } else { TEST_info("Bad encoding: %s. Should be one of " "{canonical, valid, invalid}", encoding); return 0; } t->data = edata; return 1; }
['static int encode_test_init(EVP_TEST *t, const char *encoding)\n{\n ENCODE_DATA *edata = OPENSSL_zalloc(sizeof(*edata));\n if (strcmp(encoding, "canonical") == 0) {\n edata->encoding = BASE64_CANONICAL_ENCODING;\n } else if (strcmp(encoding, "valid") == 0) {\n edata->encoding = BASE64_VALID_ENCODING;\n } else if (strcmp(encoding, "invalid") == 0) {\n edata->encoding = BASE64_INVALID_ENCODING;\n t->expected_err = OPENSSL_strdup("DECODE_ERROR");\n if (t->expected_err == NULL)\n return 0;\n } else {\n TEST_info("Bad encoding: %s. Should be one of "\n "{canonical, valid, invalid}", encoding);\n return 0;\n }\n t->data = edata;\n return 1;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'char *CRYPTO_strdup(const char *str, const char* file, int line)\n{\n char *ret;\n size_t size;\n if (str == NULL)\n return NULL;\n size = strlen(str) + 1;\n ret = CRYPTO_malloc(size, file, line);\n if (ret != NULL)\n memcpy(ret, str, size);\n return ret;\n}']
34,821
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_lib.c/#L766
int bn_cmp_words(const BN_ULONG *a, const BN_ULONG *b, int n) { int i; BN_ULONG aa, bb; aa = a[n - 1]; bb = b[n - 1]; if (aa != bb) return ((aa > bb) ? 1 : -1); for (i = n - 2; i >= 0; i--) { aa = a[i]; bb = b[i]; if (aa != bb) return ((aa > bb) ? 1 : -1); } return (0); }
['int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group,\n EC_POINT *point,\n const BIGNUM *x_, int y_bit,\n BN_CTX *ctx)\n{\n BN_CTX *new_ctx = NULL;\n BIGNUM *tmp1, *tmp2, *x, *y;\n int ret = 0;\n ERR_clear_error();\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return 0;\n }\n y_bit = (y_bit != 0);\n BN_CTX_start(ctx);\n tmp1 = BN_CTX_get(ctx);\n tmp2 = BN_CTX_get(ctx);\n x = BN_CTX_get(ctx);\n y = BN_CTX_get(ctx);\n if (y == NULL)\n goto err;\n if (!BN_nnmod(x, x_, group->field, ctx))\n goto err;\n if (group->meth->field_decode == 0) {\n if (!group->meth->field_sqr(group, tmp2, x_, ctx))\n goto err;\n if (!group->meth->field_mul(group, tmp1, tmp2, x_, ctx))\n goto err;\n } else {\n if (!BN_mod_sqr(tmp2, x_, group->field, ctx))\n goto err;\n if (!BN_mod_mul(tmp1, tmp2, x_, group->field, ctx))\n goto err;\n }\n if (group->a_is_minus3) {\n if (!BN_mod_lshift1_quick(tmp2, x, group->field))\n goto err;\n if (!BN_mod_add_quick(tmp2, tmp2, x, group->field))\n goto err;\n if (!BN_mod_sub_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n } else {\n if (group->meth->field_decode) {\n if (!group->meth->field_decode(group, tmp2, group->a, ctx))\n goto err;\n if (!BN_mod_mul(tmp2, tmp2, x, group->field, ctx))\n goto err;\n } else {\n if (!group->meth->field_mul(group, tmp2, group->a, x, ctx))\n goto err;\n }\n if (!BN_mod_add_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n }\n if (group->meth->field_decode) {\n if (!group->meth->field_decode(group, tmp2, group->b, ctx))\n goto err;\n if (!BN_mod_add_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n } else {\n if (!BN_mod_add_quick(tmp1, tmp1, group->b, group->field))\n goto err;\n }\n if (!BN_mod_sqrt(y, tmp1, group->field, ctx)) {\n unsigned long err = ERR_peek_last_error();\n if (ERR_GET_LIB(err) == ERR_LIB_BN\n && ERR_GET_REASON(err) == BN_R_NOT_A_SQUARE) {\n ERR_clear_error();\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSED_POINT);\n } else\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n ERR_R_BN_LIB);\n goto err;\n }\n if (y_bit != BN_is_odd(y)) {\n if (BN_is_zero(y)) {\n int kron;\n kron = BN_kronecker(x, group->field, ctx);\n if (kron == -2)\n goto err;\n if (kron == 1)\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSION_BIT);\n else\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSED_POINT);\n goto err;\n }\n if (!BN_usub(y, group->field, y))\n goto err;\n }\n if (y_bit != BN_is_odd(y)) {\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return (ret);\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return (1);\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n rr->neg = a->neg ^ b->neg;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# if 0\n if (i == 1 && !BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)b;\n if (bn_wexpand(tmp_bn, al) == NULL)\n goto err;\n tmp_bn->d[bl] = 0;\n bl++;\n i--;\n } else if (i == -1 && !BN_get_flags(a, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)a;\n if (bn_wexpand(tmp_bn, bl) == NULL)\n goto err;\n tmp_bn->d[al] = 0;\n al++;\n i++;\n }\n if (i == 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (al == j) {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, al, t->d);\n } else {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d, al - j, j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# endif\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n bn_correct_top(rr);\n if (r != rr)\n BN_copy(r, rr);\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return (ret);\n}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,\n int tna, int tnb, BN_ULONG *t)\n{\n int i, j, n2 = n * 2;\n int c1, c2, neg;\n BN_ULONG ln, lo, *p;\n if (n < 8) {\n bn_mul_normal(r, a, n + tna, b, n + tnb);\n return;\n }\n c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);\n c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);\n neg = 0;\n switch (c1 * 3 + c2) {\n case -4:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n break;\n case -3:\n case -2:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n neg = 1;\n break;\n case -1:\n case 0:\n case 1:\n case 2:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n neg = 1;\n break;\n case 3:\n case 4:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n break;\n }\n# if 0\n if (n == 4) {\n bn_mul_comba4(&(t[n2]), t, &(t[n]));\n bn_mul_comba4(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tn, &(b[n]), tn);\n memset(&r[n2 + tn * 2], 0, sizeof(*r) * (n2 - tn * 2));\n } else\n# endif\n if (n == 8) {\n bn_mul_comba8(&(t[n2]), t, &(t[n]));\n bn_mul_comba8(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n memset(&r[n2 + tna + tnb], 0, sizeof(*r) * (n2 - tna - tnb));\n } else {\n p = &(t[n2 * 2]);\n bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);\n bn_mul_recursive(r, a, b, n, 0, 0, p);\n i = n / 2;\n if (tna > tnb)\n j = tna - i;\n else\n j = tnb - i;\n if (j == 0) {\n bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&r[n2 + i * 2], 0, sizeof(*r) * (n2 - i * 2));\n } else if (j > 0) {\n bn_mul_part_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&(r[n2 + tna + tnb]), 0,\n sizeof(BN_ULONG) * (n2 - tna - tnb));\n } else {\n memset(&r[n2], 0, sizeof(*r) * n2);\n if (tna < BN_MUL_RECURSIVE_SIZE_NORMAL\n && tnb < BN_MUL_RECURSIVE_SIZE_NORMAL) {\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n } else {\n for (;;) {\n i /= 2;\n if (i < tna || i < tnb) {\n bn_mul_part_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n } else if (i == tna || i == tnb) {\n bn_mul_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n }\n }\n }\n }\n }\n c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));\n if (neg) {\n c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));\n } else {\n c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));\n }\n c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));\n if (c1) {\n p = &(r[n + n2]);\n lo = *p;\n ln = (lo + c1) & BN_MASK2;\n *p = ln;\n if (ln < (BN_ULONG)c1) {\n do {\n p++;\n lo = *p;\n ln = (lo + 1) & BN_MASK2;\n *p = ln;\n } while (ln == 0);\n }\n }\n}', 'int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b, int cl, int dl)\n{\n int n, i;\n n = cl - 1;\n if (dl < 0) {\n for (i = dl; i < 0; i++) {\n if (b[n - i] != 0)\n return -1;\n }\n }\n if (dl > 0) {\n for (i = dl; i > 0; i--) {\n if (a[n + i] != 0)\n return 1;\n }\n }\n return bn_cmp_words(a, b, cl);\n}', 'int bn_cmp_words(const BN_ULONG *a, const BN_ULONG *b, int n)\n{\n int i;\n BN_ULONG aa, bb;\n aa = a[n - 1];\n bb = b[n - 1];\n if (aa != bb)\n return ((aa > bb) ? 1 : -1);\n for (i = n - 2; i >= 0; i--) {\n aa = a[i];\n bb = b[i];\n if (aa != bb)\n return ((aa > bb) ? 1 : -1);\n }\n return (0);\n}']
34,822
0
https://github.com/libav/libav/blob/3567b91e49c6ae101c9a35c90f46b8ad9890ac15/libavformat/utils.c/#L2469
void avformat_free_context(AVFormatContext *s) { int i, j; AVStream *st; if (!s) return; av_opt_free(s); if (s->iformat && s->iformat->priv_class && s->priv_data) av_opt_free(s->priv_data); for (i = 0; i < s->nb_streams; i++) { st = s->streams[i]; for (j = 0; j < st->nb_side_data; j++) av_freep(&st->side_data[j].data); av_freep(&st->side_data); st->nb_side_data = 0; if (st->parser) { av_parser_close(st->parser); } if (st->attached_pic.data) av_free_packet(&st->attached_pic); av_dict_free(&st->metadata); av_freep(&st->probe_data.buf); av_free(st->index_entries); av_free(st->codec->extradata); av_free(st->codec->subtitle_header); av_free(st->codec); av_free(st->priv_data); av_free(st->info); av_free(st); } for (i = s->nb_programs - 1; i >= 0; i--) { av_dict_free(&s->programs[i]->metadata); av_freep(&s->programs[i]->stream_index); av_freep(&s->programs[i]); } av_freep(&s->programs); av_freep(&s->priv_data); while (s->nb_chapters--) { av_dict_free(&s->chapters[s->nb_chapters]->metadata); av_free(s->chapters[s->nb_chapters]); } av_freep(&s->chapters); av_dict_free(&s->metadata); av_freep(&s->streams); av_freep(&s->internal); av_free(s); }
['void ff_rtsp_close_streams(AVFormatContext *s)\n{\n RTSPState *rt = s->priv_data;\n int i, j;\n RTSPStream *rtsp_st;\n ff_rtsp_undo_setup(s, 0);\n for (i = 0; i < rt->nb_rtsp_streams; i++) {\n rtsp_st = rt->rtsp_streams[i];\n if (rtsp_st) {\n if (rtsp_st->dynamic_handler && rtsp_st->dynamic_protocol_context) {\n if (rtsp_st->dynamic_handler->free)\n rtsp_st->dynamic_handler->free(\n rtsp_st->dynamic_protocol_context);\n else\n av_free(rtsp_st->dynamic_protocol_context);\n }\n for (j = 0; j < rtsp_st->nb_include_source_addrs; j++)\n av_free(rtsp_st->include_source_addrs[j]);\n av_freep(&rtsp_st->include_source_addrs);\n for (j = 0; j < rtsp_st->nb_exclude_source_addrs; j++)\n av_free(rtsp_st->exclude_source_addrs[j]);\n av_freep(&rtsp_st->exclude_source_addrs);\n av_free(rtsp_st);\n }\n }\n av_free(rt->rtsp_streams);\n if (rt->asf_ctx) {\n avformat_close_input(&rt->asf_ctx);\n }\n if (CONFIG_RTPDEC && rt->ts)\n ff_mpegts_parse_close(rt->ts);\n av_free(rt->p);\n av_free(rt->recvbuf);\n}', 'void avformat_close_input(AVFormatContext **ps)\n{\n AVFormatContext *s = *ps;\n AVIOContext *pb = s->pb;\n if ((s->iformat && s->iformat->flags & AVFMT_NOFILE) ||\n (s->flags & AVFMT_FLAG_CUSTOM_IO))\n pb = NULL;\n flush_packet_queue(s);\n if (s->iformat)\n if (s->iformat->read_close)\n s->iformat->read_close(s);\n avformat_free_context(s);\n *ps = NULL;\n avio_close(pb);\n}', 'void avformat_free_context(AVFormatContext *s)\n{\n int i, j;\n AVStream *st;\n if (!s)\n return;\n av_opt_free(s);\n if (s->iformat && s->iformat->priv_class && s->priv_data)\n av_opt_free(s->priv_data);\n for (i = 0; i < s->nb_streams; i++) {\n st = s->streams[i];\n for (j = 0; j < st->nb_side_data; j++)\n av_freep(&st->side_data[j].data);\n av_freep(&st->side_data);\n st->nb_side_data = 0;\n if (st->parser) {\n av_parser_close(st->parser);\n }\n if (st->attached_pic.data)\n av_free_packet(&st->attached_pic);\n av_dict_free(&st->metadata);\n av_freep(&st->probe_data.buf);\n av_free(st->index_entries);\n av_free(st->codec->extradata);\n av_free(st->codec->subtitle_header);\n av_free(st->codec);\n av_free(st->priv_data);\n av_free(st->info);\n av_free(st);\n }\n for (i = s->nb_programs - 1; i >= 0; i--) {\n av_dict_free(&s->programs[i]->metadata);\n av_freep(&s->programs[i]->stream_index);\n av_freep(&s->programs[i]);\n }\n av_freep(&s->programs);\n av_freep(&s->priv_data);\n while (s->nb_chapters--) {\n av_dict_free(&s->chapters[s->nb_chapters]->metadata);\n av_free(s->chapters[s->nb_chapters]);\n }\n av_freep(&s->chapters);\n av_dict_free(&s->metadata);\n av_freep(&s->streams);\n av_freep(&s->internal);\n av_free(s);\n}']
34,823
0
https://github.com/openssl/openssl/blob/9c46f4b9cd4912b61cb546c48b678488d7f26ed6/crypto/bn/bn_ctx.c/#L353
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['BIGNUM *SRP_Calc_client_key(BIGNUM *N, BIGNUM *B, BIGNUM *g, BIGNUM *x,\n BIGNUM *a, BIGNUM *u)\n{\n BIGNUM *tmp = NULL, *tmp2 = NULL, *tmp3 = NULL, *k = NULL, *K = NULL;\n BN_CTX *bn_ctx;\n if (u == NULL || B == NULL || N == NULL || g == NULL || x == NULL\n || a == NULL || (bn_ctx = BN_CTX_new()) == NULL)\n return NULL;\n if ((tmp = BN_new()) == NULL ||\n (tmp2 = BN_new()) == NULL ||\n (tmp3 = BN_new()) == NULL || (K = BN_new()) == NULL)\n goto err;\n if (!BN_mod_exp(tmp, g, x, N, bn_ctx))\n goto err;\n if (!(k = srp_Calc_k(N, g)))\n goto err;\n if (!BN_mod_mul(tmp2, tmp, k, N, bn_ctx))\n goto err;\n if (!BN_mod_sub(tmp, B, tmp2, N, bn_ctx))\n goto err;\n if (!BN_mod_mul(tmp3, u, x, N, bn_ctx))\n goto err;\n if (!BN_mod_add(tmp2, a, tmp3, N, bn_ctx))\n goto err;\n if (!BN_mod_exp(K, tmp, tmp2, N, bn_ctx))\n goto err;\n err:\n BN_CTX_free(bn_ctx);\n BN_clear_free(tmp);\n BN_clear_free(tmp2);\n BN_clear_free(tmp3);\n BN_free(k);\n return K;\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return (ret);\n}', 'int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_RECP_CTX recp;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_RECP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return -1;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n ret = BN_one(r);\n return ret;\n }\n BN_CTX_start(ctx);\n aa = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (!aa || !val[0])\n goto err;\n BN_RECP_CTX_init(&recp);\n if (m->neg) {\n if (!BN_copy(aa, m))\n goto err;\n aa->neg = 0;\n if (BN_RECP_CTX_set(&recp, aa, ctx) <= 0)\n goto err;\n } else {\n if (BN_RECP_CTX_set(&recp, m, ctx) <= 0)\n goto err;\n }\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n if (BN_is_zero(val[0])) {\n BN_zero(r);\n ret = 1;\n goto err;\n }\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_reciprocal(aa, val[0], val[0], &recp, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_reciprocal(val[i], val[i - 1], aa, &recp, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n if (!BN_one(r))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start)\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n }\n if (!BN_mod_mul_reciprocal(r, r, val[wvalue >> 1], &recp, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_RECP_CTX_free(&recp);\n bn_check_top(r);\n return (ret);\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return (1);\n }\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (dv == NULL)\n res = BN_CTX_get(ctx);\n else\n res = dv;\n if (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n res->neg = (num->neg ^ divisor->neg);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--, resp--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# ifdef BN_DEBUG_LEVITTE\n fprintf(stderr, "DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n", n0, n1, d0, q);\n# endif\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifdef BN_DEBUG_LEVITTE\n fprintf(stderr, "DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n", n0, n1, d0, q);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return (1);\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return (0);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
34,824
0
https://github.com/libav/libav/blob/6aa4e88106a554cef1d2294bb0a18b8f843032ef/libavfilter/formats.c/#L261
void ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref) { FORMATS_REF(f, ref); }
['void ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)\n{\n FORMATS_REF(f, ref);\n}', 'void *av_realloc(void *ptr, size_t size)\n{\n#if CONFIG_MEMALIGN_HACK\n int diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n if(!ptr) return av_malloc(size);\n diff= ((char*)ptr)[-1];\n return (char*)realloc((char*)ptr - diff, size + diff) + diff;\n#elif HAVE_ALIGNED_MALLOC\n return _aligned_realloc(ptr, size, 32);\n#else\n return realloc(ptr, size);\n#endif\n}']
34,825
0
https://github.com/openssl/openssl/blob/52a1bab2d9891810618569e6c744375b768fce8c/crypto/lhash/lhash.c/#L289
void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg) { int i; LHASH_NODE *a,*n; for (i=lh->num_nodes-1; i>=0; i--) { a=lh->b[i]; while (a != NULL) { n=a->next; func(a->data,arg); a=n; } } }
['void CRYPTO_mem_leaks(BIO *b)\n\t{\n\tMEM_LEAK ml;\n\tchar buf[80];\n\tif (mh == NULL && amih == NULL)\n\t\treturn;\n\tml.bio=b;\n\tml.bytes=0;\n\tml.chunks=0;\n\tMemCheck_off();\n\tif (mh != NULL)\n\t\tlh_doall_arg(mh, (LHASH_DOALL_ARG_FN_TYPE)print_leak,\n\t\t\t\t(char *)&ml);\n\tif (ml.chunks != 0)\n\t\t{\n\t\tsprintf(buf,"%ld bytes leaked in %d chunks\\n",\n\t\t\tml.bytes,ml.chunks);\n\t\tBIO_puts(b,buf);\n\t\t}\n\telse\n\t\t{\n\t\tCRYPTO_w_lock(CRYPTO_LOCK_MALLOC);\n\t\tif (mh != NULL)\n\t\t\t{\n\t\t\tlh_free(mh);\n\t\t\tmh = NULL;\n\t\t\t}\n\t\tif (amih != NULL)\n\t\t\t{\n\t\t\tif (lh_num_items(amih) == 0)\n\t\t\t\t{\n\t\t\t\tlh_free(amih);\n\t\t\t\tamih = NULL;\n\t\t\t\t}\n\t\t\t}\n\t\tCRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);\n\t\t}\n\tMemCheck_on();\n#if 0\n\tlh_stats_bio(mh,b);\n\tlh_node_stats_bio(mh,b);\n\tlh_node_usage_stats_bio(mh,b);\n#endif\n\t}', 'void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg)\n\t{\n\tint i;\n\tLHASH_NODE *a,*n;\n\tfor (i=lh->num_nodes-1; i>=0; i--)\n\t\t{\n\t\ta=lh->b[i];\n\t\twhile (a != NULL)\n\t\t\t{\n\t\t\tn=a->next;\n\t\t\tfunc(a->data,arg);\n\t\t\ta=n;\n\t\t\t}\n\t\t}\n\t}']
34,826
0
https://github.com/libav/libav/blob/0526c6f7c7852730e4d3da3dd1d070deb00e5043/libavcodec/ffv1.c/#L328
static void find_best_state(uint8_t best_state[256][256], const uint8_t one_state[256]){ int i,j,k,m; double l2tab[256]; for(i=1; i<256; i++) l2tab[i]= log2(i/256.0); for(i=0; i<256; i++){ double best_len[256]; double p= i/256.0; for(j=0; j<256; j++) best_len[j]= 1<<30; for(j=FFMAX(i-10,1); j<FFMIN(i+11,256); j++){ double occ[256]={0}; double len=0; occ[j]=1.0; for(k=0; k<256; k++){ double newocc[256]={0}; for(m=0; m<256; m++){ if(occ[m]){ len -=occ[m]*( p *l2tab[ m] + (1-p)*l2tab[256-m]); } } if(len < best_len[k]){ best_len[k]= len; best_state[i][k]= j; } for(m=0; m<256; m++){ if(occ[m]){ newocc[ one_state[ m]] += occ[m]* p ; newocc[256-one_state[256-m]] += occ[m]*(1-p); } } memcpy(occ, newocc, sizeof(occ)); } } } }
['static void find_best_state(uint8_t best_state[256][256], const uint8_t one_state[256]){\n int i,j,k,m;\n double l2tab[256];\n for(i=1; i<256; i++)\n l2tab[i]= log2(i/256.0);\n for(i=0; i<256; i++){\n double best_len[256];\n double p= i/256.0;\n for(j=0; j<256; j++)\n best_len[j]= 1<<30;\n for(j=FFMAX(i-10,1); j<FFMIN(i+11,256); j++){\n double occ[256]={0};\n double len=0;\n occ[j]=1.0;\n for(k=0; k<256; k++){\n double newocc[256]={0};\n for(m=0; m<256; m++){\n if(occ[m]){\n len -=occ[m]*( p *l2tab[ m]\n + (1-p)*l2tab[256-m]);\n }\n }\n if(len < best_len[k]){\n best_len[k]= len;\n best_state[i][k]= j;\n }\n for(m=0; m<256; m++){\n if(occ[m]){\n newocc[ one_state[ m]] += occ[m]* p ;\n newocc[256-one_state[256-m]] += occ[m]*(1-p);\n }\n }\n memcpy(occ, newocc, sizeof(occ));\n }\n }\n }\n}']
34,827
0
https://github.com/openssl/openssl/blob/14c6d27d63795ead1b70d97e3303731b433c0db8/crypto/bn/bn_ctx.c/#L143
void BN_CTX_end(BN_CTX *ctx) { if (ctx == NULL) return; assert(ctx->depth > 0); if (ctx->depth == 0) BN_CTX_start(ctx); ctx->too_many = 0; ctx->depth--; if (ctx->depth < BN_CTX_NUM_POS) ctx->tos = ctx->pos[ctx->depth]; }
['static int RSA_eay_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa)\n\t{\n\tconst RSA_METHOD *meth;\n\tBIGNUM r1,m1;\n\tint ret=0;\n\tBN_CTX *ctx;\n\tmeth = ENGINE_get_RSA(rsa->engine);\n\tif ((ctx=BN_CTX_new()) == NULL) goto err;\n\tBN_init(&m1);\n\tBN_init(&r1);\n\tif (rsa->flags & RSA_FLAG_CACHE_PRIVATE)\n\t\t{\n\t\tif (rsa->_method_mod_p == NULL)\n\t\t\t{\n\t\t\tif ((rsa->_method_mod_p=BN_MONT_CTX_new()) != NULL)\n\t\t\t\tif (!BN_MONT_CTX_set(rsa->_method_mod_p,rsa->p,\n\t\t\t\t\t\t ctx))\n\t\t\t\t\tgoto err;\n\t\t\t}\n\t\tif (rsa->_method_mod_q == NULL)\n\t\t\t{\n\t\t\tif ((rsa->_method_mod_q=BN_MONT_CTX_new()) != NULL)\n\t\t\t\tif (!BN_MONT_CTX_set(rsa->_method_mod_q,rsa->q,\n\t\t\t\t\t\t ctx))\n\t\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tif (!BN_mod(&r1,I,rsa->q,ctx)) goto err;\n\tif (!meth->bn_mod_exp(&m1,&r1,rsa->dmq1,rsa->q,ctx,\n\t\trsa->_method_mod_q)) goto err;\n\tif (!BN_mod(&r1,I,rsa->p,ctx)) goto err;\n\tif (!meth->bn_mod_exp(r0,&r1,rsa->dmp1,rsa->p,ctx,\n\t\trsa->_method_mod_p)) goto err;\n\tif (!BN_sub(r0,r0,&m1)) goto err;\n\tif (r0->neg)\n\t\tif (!BN_add(r0,r0,rsa->p)) goto err;\n\tif (!BN_mul(&r1,r0,rsa->iqmp,ctx)) goto err;\n\tif (!BN_mod(r0,&r1,rsa->p,ctx)) goto err;\n\tif (r0->neg)\n\t\tif (!BN_add(r0,r0,rsa->p)) goto err;\n\tif (!BN_mul(&r1,r0,rsa->q,ctx)) goto err;\n\tif (!BN_add(r0,&r1,&m1)) goto err;\n\tret=1;\nerr:\n\tBN_clear_free(&m1);\n\tBN_clear_free(&r1);\n\tBN_CTX_free(ctx);\n\treturn(ret);\n\t}', 'BN_CTX *BN_CTX_new(void)\n\t{\n\tBN_CTX *ret;\n\tret=(BN_CTX *)OPENSSL_malloc(sizeof(BN_CTX));\n\tif (ret == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tBN_CTX_init(ret);\n\tret->flags=BN_FLG_MALLOCED;\n\treturn(ret);\n\t}', 'void BN_CTX_init(BN_CTX *ctx)\n\t{\n\tint i;\n\tctx->tos = 0;\n\tctx->flags = 0;\n\tctx->depth = 0;\n\tctx->too_many = 0;\n\tfor (i = 0; i < BN_CTX_NUM; i++)\n\t\tBN_init(&(ctx->bn[i]));\n\t}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tBIGNUM Ri,*R;\n\tBN_init(&Ri);\n\tR= &(mont->RR);\n\tBN_copy(&(mont->N),mod);\n#ifdef MONT_WORD\n\t\t{\n\t\tBIGNUM tmod;\n\t\tBN_ULONG buf[2];\n\t\tmont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;\n\t\tBN_zero(R);\n\t\tBN_set_bit(R,BN_BITS2);\n\t\tbuf[0]=mod->d[0];\n\t\tbuf[1]=0;\n\t\ttmod.d=buf;\n\t\ttmod.top=1;\n\t\ttmod.dmax=2;\n\t\ttmod.neg=mod->neg;\n\t\tif ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tBN_lshift(&Ri,&Ri,BN_BITS2);\n\t\tif (!BN_is_zero(&Ri))\n\t\t\tBN_sub_word(&Ri,1);\n\t\telse\n\t\t\tBN_set_word(&Ri,BN_MASK2);\n\t\tBN_div(&Ri,NULL,&Ri,&tmod,ctx);\n\t\tmont->n0=Ri.d[0];\n\t\tBN_free(&Ri);\n\t\t}\n#else\n\t\t{\n\t\tmont->ri=BN_num_bits(mod);\n\t\tBN_zero(R);\n\t\tBN_set_bit(R,mont->ri);\n\t\tif ((BN_mod_inverse(&Ri,R,mod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tBN_lshift(&Ri,&Ri,mont->ri);\n\t\tBN_sub_word(&Ri,1);\n\t\tBN_div(&(mont->Ni),NULL,&Ri,mod,ctx);\n\t\tBN_free(&Ri);\n\t\t}\n#endif\n\tBN_zero(&(mont->RR));\n\tBN_set_bit(&(mont->RR),mont->ri*2);\n\tBN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx);\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'BIGNUM *BN_mod_inverse(BIGNUM *in, BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n\t{\n\tBIGNUM *A,*B,*X,*Y,*M,*D,*R=NULL;\n\tBIGNUM *T,*ret=NULL;\n\tint sign;\n\tbn_check_top(a);\n\tbn_check_top(n);\n\tBN_CTX_start(ctx);\n\tA = BN_CTX_get(ctx);\n\tB = BN_CTX_get(ctx);\n\tX = BN_CTX_get(ctx);\n\tD = BN_CTX_get(ctx);\n\tM = BN_CTX_get(ctx);\n\tY = BN_CTX_get(ctx);\n\tif (Y == NULL) goto err;\n\tif (in == NULL)\n\t\tR=BN_new();\n\telse\n\t\tR=in;\n\tif (R == NULL) goto err;\n\tBN_zero(X);\n\tBN_one(Y);\n\tif (BN_copy(A,a) == NULL) goto err;\n\tif (BN_copy(B,n) == NULL) goto err;\n\tsign=1;\n\twhile (!BN_is_zero(B))\n\t\t{\n\t\tif (!BN_div(D,M,A,B,ctx)) goto err;\n\t\tT=A;\n\t\tA=B;\n\t\tB=M;\n\t\tif (!BN_mul(T,D,X,ctx)) goto err;\n\t\tif (!BN_add(T,T,Y)) goto err;\n\t\tM=Y;\n\t\tY=X;\n\t\tX=T;\n\t\tsign= -sign;\n\t\t}\n\tif (sign < 0)\n\t\t{\n\t\tif (!BN_sub(Y,n,Y)) goto err;\n\t\t}\n\tif (BN_is_one(A))\n\t\t{ if (!BN_mod(R,Y,n,ctx)) goto err; }\n\telse\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE);\n\t\tgoto err;\n\t\t}\n\tret=R;\nerr:\n\tif ((ret == NULL) && (in == NULL)) BN_free(R);\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tif (ctx->depth < BN_CTX_NUM_POS)\n\t\tctx->pos[ctx->depth] = ctx->tos;\n\tctx->depth++;\n\t}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n\t{\n\tif (ctx->depth > BN_CTX_NUM_POS || ctx->tos >= BN_CTX_NUM)\n\t\t{\n\t\tif (!ctx->too_many)\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_CTX_GET,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\t\tctx->too_many = 1;\n\t\t\t}\n\t\treturn NULL;\n\t\t}\n\treturn (&(ctx->bn[ctx->tos++]));\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tif (ctx == NULL) return;\n\tassert(ctx->depth > 0);\n\tif (ctx->depth == 0)\n\t\tBN_CTX_start(ctx);\n\tctx->too_many = 0;\n\tctx->depth--;\n\tif (ctx->depth < BN_CTX_NUM_POS)\n\t\tctx->tos = ctx->pos[ctx->depth];\n\t}']
34,828
0
https://github.com/openssl/openssl/blob/80aa9cc985251463a3ad65b0a4d64bf93c70b175/crypto/bn/bn_lib.c/#L615
BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret) { unsigned int i,m; unsigned int n; BN_ULONG l; BIGNUM *bn = NULL; if (ret == NULL) ret = bn = BN_new(); if (ret == NULL) return(NULL); bn_check_top(ret); l=0; n=len; if (n == 0) { ret->top=0; return(ret); } i=((n-1)/BN_BYTES)+1; m=((n-1)%(BN_BYTES)); if (bn_wexpand(ret, (int)i) == NULL) { if (bn) BN_free(bn); return NULL; } ret->top=i; ret->neg=0; while (n--) { l=(l<<8L)| *(s++); if (m-- == 0) { ret->d[--i]=l; l=0; m=BN_BYTES-1; } } bn_correct_top(ret); return(ret); }
['static int sv_body(char *hostname, int s, unsigned char *context)\n\t{\n\tchar *buf=NULL;\n\tfd_set readfds;\n\tint ret=1,width;\n\tint k,i;\n\tunsigned long l;\n\tSSL *con=NULL;\n\tBIO *sbio;\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE) || defined(OPENSSL_SYS_BEOS_R5)\n\tstruct timeval tv;\n#endif\n\tif ((buf=OPENSSL_malloc(bufsize)) == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"out of memory\\n");\n\t\tgoto err;\n\t\t}\n#ifdef FIONBIO\n\tif (s_nbio)\n\t\t{\n\t\tunsigned long sl=1;\n\t\tif (!s_quiet)\n\t\t\tBIO_printf(bio_err,"turning on non blocking io\\n");\n\t\tif (BIO_socket_ioctl(s,FIONBIO,&sl) < 0)\n\t\t\tERR_print_errors(bio_err);\n\t\t}\n#endif\n\tif (con == NULL) {\n\t\tcon=SSL_new(ctx);\n#ifndef OPENSSL_NO_TLSEXT\n\tif (s_tlsextdebug)\n\t\t{\n\t\tSSL_set_tlsext_debug_callback(con, tlsext_cb);\n\t\tSSL_set_tlsext_debug_arg(con, bio_s_out);\n\t\t}\n\tif (s_tlsextstatus)\n\t\t{\n\t\tSSL_CTX_set_tlsext_status_cb(ctx, cert_status_cb);\n\t\ttlscstatp.err = bio_err;\n\t\tSSL_CTX_set_tlsext_status_arg(ctx, &tlscstatp);\n\t\t}\n#endif\n#ifndef OPENSSL_NO_KRB5\n\t\tif ((con->kssl_ctx = kssl_ctx_new()) != NULL)\n {\n kssl_ctx_setstring(con->kssl_ctx, KSSL_SERVICE,\n\t\t\t\t\t\t\t\tKRB5SVC);\n kssl_ctx_setstring(con->kssl_ctx, KSSL_KEYTAB,\n\t\t\t\t\t\t\t\tKRB5KEYTAB);\n }\n#endif\n\t\tif(context)\n\t\t SSL_set_session_id_context(con, context,\n\t\t\t\t\t\t strlen((char *)context));\n\t}\n\tSSL_clear(con);\n#if 0\n#ifdef TLSEXT_TYPE_opaque_prf_input\n\tSSL_set_tlsext_opaque_prf_input(con, "Test server", 11);\n#endif\n#endif\n\tif (SSL_version(con) == DTLS1_VERSION)\n\t\t{\n\t\tstruct timeval timeout;\n\t\tsbio=BIO_new_dgram(s,BIO_NOCLOSE);\n\t\tif (enable_timeouts)\n\t\t\t{\n\t\t\ttimeout.tv_sec = 0;\n\t\t\ttimeout.tv_usec = DGRAM_RCV_TIMEOUT;\n\t\t\tBIO_ctrl(sbio, BIO_CTRL_DGRAM_SET_RECV_TIMEOUT, 0, &timeout);\n\t\t\ttimeout.tv_sec = 0;\n\t\t\ttimeout.tv_usec = DGRAM_SND_TIMEOUT;\n\t\t\tBIO_ctrl(sbio, BIO_CTRL_DGRAM_SET_SEND_TIMEOUT, 0, &timeout);\n\t\t\t}\n\t\tif (socket_mtu > 0)\n\t\t\t{\n\t\t\tSSL_set_options(con, SSL_OP_NO_QUERY_MTU);\n\t\t\tSSL_set_mtu(con, socket_mtu);\n\t\t\t}\n\t\telse\n\t\t\tBIO_ctrl(sbio, BIO_CTRL_DGRAM_MTU_DISCOVER, 0, NULL);\n SSL_set_options(con, SSL_OP_COOKIE_EXCHANGE);\n\t\t}\n\telse\n\t\tsbio=BIO_new_socket(s,BIO_NOCLOSE);\n\tif (s_nbio_test)\n\t\t{\n\t\tBIO *test;\n\t\ttest=BIO_new(BIO_f_nbio_test());\n\t\tsbio=BIO_push(test,sbio);\n\t\t}\n\tif(jpake_secret)\n\t\tjpake_server_auth(bio_s_out, sbio, jpake_secret);\n\tSSL_set_bio(con,sbio,sbio);\n\tSSL_set_accept_state(con);\n\tif (s_debug)\n\t\t{\n\t\tcon->debug=1;\n\t\tBIO_set_callback(SSL_get_rbio(con),bio_dump_callback);\n\t\tBIO_set_callback_arg(SSL_get_rbio(con),(char *)bio_s_out);\n\t\t}\n\tif (s_msg)\n\t\t{\n\t\tSSL_set_msg_callback(con, msg_cb);\n\t\tSSL_set_msg_callback_arg(con, bio_s_out);\n\t\t}\n#ifndef OPENSSL_NO_TLSEXT\n\tif (s_tlsextdebug)\n\t\t{\n\t\tSSL_set_tlsext_debug_callback(con, tlsext_cb);\n\t\tSSL_set_tlsext_debug_arg(con, bio_s_out);\n\t\t}\n#endif\n\twidth=s+1;\n\tfor (;;)\n\t\t{\n\t\tint read_from_terminal;\n\t\tint read_from_sslcon;\n\t\tread_from_terminal = 0;\n\t\tread_from_sslcon = SSL_pending(con);\n\t\tif (!read_from_sslcon)\n\t\t\t{\n\t\t\tFD_ZERO(&readfds);\n#if !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_NETWARE) && !defined(OPENSSL_SYS_BEOS_R5)\n\t\t\topenssl_fdset(fileno(stdin),&readfds);\n#endif\n\t\t\topenssl_fdset(s,&readfds);\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE)\n\t\t\ttv.tv_sec = 1;\n\t\t\ttv.tv_usec = 0;\n\t\t\ti=select(width,(void *)&readfds,NULL,NULL,&tv);\n\t\t\tif((i < 0) || (!i && !_kbhit() ) )continue;\n\t\t\tif(_kbhit())\n\t\t\t\tread_from_terminal = 1;\n#elif defined(OPENSSL_SYS_BEOS_R5)\n\t\t\ttv.tv_sec = 1;\n\t\t\ttv.tv_usec = 0;\n\t\t\t(void)fcntl(fileno(stdin), F_SETFL, O_NONBLOCK);\n\t\t\ti=select(width,(void *)&readfds,NULL,NULL,&tv);\n\t\t\tif ((i < 0) || (!i && read(fileno(stdin), buf, 0) < 0))\n\t\t\t\tcontinue;\n\t\t\tif (read(fileno(stdin), buf, 0) >= 0)\n\t\t\t\tread_from_terminal = 1;\n\t\t\t(void)fcntl(fileno(stdin), F_SETFL, 0);\n#else\n\t\t\ti=select(width,(void *)&readfds,NULL,NULL,NULL);\n\t\t\tif (i <= 0) continue;\n\t\t\tif (FD_ISSET(fileno(stdin),&readfds))\n\t\t\t\tread_from_terminal = 1;\n#endif\n\t\t\tif (FD_ISSET(s,&readfds))\n\t\t\t\tread_from_sslcon = 1;\n\t\t\t}\n\t\tif (read_from_terminal)\n\t\t\t{\n\t\t\tif (s_crlf)\n\t\t\t\t{\n\t\t\t\tint j, lf_num;\n\t\t\t\ti=raw_read_stdin(buf, bufsize/2);\n\t\t\t\tlf_num = 0;\n\t\t\t\tfor (j = 0; j < i; j++)\n\t\t\t\t\tif (buf[j] == \'\\n\')\n\t\t\t\t\t\tlf_num++;\n\t\t\t\tfor (j = i-1; j >= 0; j--)\n\t\t\t\t\t{\n\t\t\t\t\tbuf[j+lf_num] = buf[j];\n\t\t\t\t\tif (buf[j] == \'\\n\')\n\t\t\t\t\t\t{\n\t\t\t\t\t\tlf_num--;\n\t\t\t\t\t\ti++;\n\t\t\t\t\t\tbuf[j+lf_num] = \'\\r\';\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\tassert(lf_num == 0);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\ti=raw_read_stdin(buf,bufsize);\n\t\t\tif (!s_quiet)\n\t\t\t\t{\n\t\t\t\tif ((i <= 0) || (buf[0] == \'Q\'))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_s_out,"DONE\\n");\n\t\t\t\t\tSHUTDOWN(s);\n\t\t\t\t\tclose_accept_socket();\n\t\t\t\t\tret= -11;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\tif ((i <= 0) || (buf[0] == \'q\'))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_s_out,"DONE\\n");\n\t\t\t\t\tif (SSL_version(con) != DTLS1_VERSION)\n SHUTDOWN(s);\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\tif ((buf[0] == \'r\') &&\n\t\t\t\t\t((buf[1] == \'\\n\') || (buf[1] == \'\\r\')))\n\t\t\t\t\t{\n\t\t\t\t\tSSL_renegotiate(con);\n\t\t\t\t\ti=SSL_do_handshake(con);\n\t\t\t\t\tprintf("SSL_do_handshake -> %d\\n",i);\n\t\t\t\t\ti=0;\n\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\tif ((buf[0] == \'R\') &&\n\t\t\t\t\t((buf[1] == \'\\n\') || (buf[1] == \'\\r\')))\n\t\t\t\t\t{\n\t\t\t\t\tSSL_set_verify(con,\n\t\t\t\t\t\tSSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,NULL);\n\t\t\t\t\tSSL_renegotiate(con);\n\t\t\t\t\ti=SSL_do_handshake(con);\n\t\t\t\t\tprintf("SSL_do_handshake -> %d\\n",i);\n\t\t\t\t\ti=0;\n\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\tif (buf[0] == \'P\')\n\t\t\t\t\t{\n\t\t\t\t\tstatic const char *str="Lets print some clear text\\n";\n\t\t\t\t\tBIO_write(SSL_get_wbio(con),str,strlen(str));\n\t\t\t\t\t}\n\t\t\t\tif (buf[0] == \'S\')\n\t\t\t\t\t{\n\t\t\t\t\tprint_stats(bio_s_out,SSL_get_SSL_CTX(con));\n\t\t\t\t\t}\n\t\t\t\t}\n#ifdef CHARSET_EBCDIC\n\t\t\tebcdic2ascii(buf,buf,i);\n#endif\n\t\t\tl=k=0;\n\t\t\tfor (;;)\n\t\t\t\t{\n#ifdef RENEG\n{ static count=0; if (++count == 100) { count=0; SSL_renegotiate(con); } }\n#endif\n\t\t\t\tk=SSL_write(con,&(buf[l]),(unsigned int)i);\n\t\t\t\tswitch (SSL_get_error(con,k))\n\t\t\t\t\t{\n\t\t\t\tcase SSL_ERROR_NONE:\n\t\t\t\t\tbreak;\n\t\t\t\tcase SSL_ERROR_WANT_WRITE:\n\t\t\t\tcase SSL_ERROR_WANT_READ:\n\t\t\t\tcase SSL_ERROR_WANT_X509_LOOKUP:\n\t\t\t\t\tBIO_printf(bio_s_out,"Write BLOCK\\n");\n\t\t\t\t\tbreak;\n\t\t\t\tcase SSL_ERROR_SYSCALL:\n\t\t\t\tcase SSL_ERROR_SSL:\n\t\t\t\t\tBIO_printf(bio_s_out,"ERROR\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\tcase SSL_ERROR_ZERO_RETURN:\n\t\t\t\t\tBIO_printf(bio_s_out,"DONE\\n");\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\tl+=k;\n\t\t\t\ti-=k;\n\t\t\t\tif (i <= 0) break;\n\t\t\t\t}\n\t\t\t}\n\t\tif (read_from_sslcon)\n\t\t\t{\n\t\t\tif (!SSL_is_init_finished(con))\n\t\t\t\t{\n\t\t\t\ti=init_ssl_connection(con);\n\t\t\t\tif (i < 0)\n\t\t\t\t\t{\n\t\t\t\t\tret=0;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\telse if (i == 0)\n\t\t\t\t\t{\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\nagain:\n\t\t\t\ti=SSL_read(con,(char *)buf,bufsize);\n\t\t\t\tswitch (SSL_get_error(con,i))\n\t\t\t\t\t{\n\t\t\t\tcase SSL_ERROR_NONE:\n#ifdef CHARSET_EBCDIC\n\t\t\t\t\tascii2ebcdic(buf,buf,i);\n#endif\n\t\t\t\t\traw_write_stdout(buf,\n\t\t\t\t\t\t(unsigned int)i);\n\t\t\t\t\tif (SSL_pending(con)) goto again;\n\t\t\t\t\tbreak;\n\t\t\t\tcase SSL_ERROR_WANT_WRITE:\n\t\t\t\tcase SSL_ERROR_WANT_READ:\n\t\t\t\tcase SSL_ERROR_WANT_X509_LOOKUP:\n\t\t\t\t\tBIO_printf(bio_s_out,"Read BLOCK\\n");\n\t\t\t\t\tbreak;\n\t\t\t\tcase SSL_ERROR_SYSCALL:\n\t\t\t\tcase SSL_ERROR_SSL:\n\t\t\t\t\tBIO_printf(bio_s_out,"ERROR\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\tcase SSL_ERROR_ZERO_RETURN:\n\t\t\t\t\tBIO_printf(bio_s_out,"DONE\\n");\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\nerr:\n\tif (con != NULL)\n\t\t{\n\t\tBIO_printf(bio_s_out,"shutting down SSL\\n");\n#if 1\n\t\tSSL_set_shutdown(con,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);\n#else\n\t\tSSL_shutdown(con);\n#endif\n\t\tSSL_free(con);\n\t\t}\n\tBIO_printf(bio_s_out,"CONNECTION CLOSED\\n");\n\tif (buf != NULL)\n\t\t{\n\t\tOPENSSL_cleanse(buf,bufsize);\n\t\tOPENSSL_free(buf);\n\t\t}\n\tif (ret >= 0)\n\t\tBIO_printf(bio_s_out,"ACCEPT\\n");\n\treturn(ret);\n\t}', 'BIO *BIO_new(BIO_METHOD *method)\n\t{\n\tBIO *ret=NULL;\n\tret=(BIO *)OPENSSL_malloc(sizeof(BIO));\n\tif (ret == NULL)\n\t\t{\n\t\tBIOerr(BIO_F_BIO_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tif (!BIO_set(ret,method))\n\t\t{\n\t\tOPENSSL_free(ret);\n\t\tret=NULL;\n\t\t}\n\treturn(ret);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n#ifndef OPENSSL_CPUID_OBJ\n if(ret && (num > 2048))\n\t{\textern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\t}\n#endif\n\treturn ret;\n\t}', 'void jpake_server_auth(BIO *out, BIO *conn, const char *secret)\n\t{\n\tJPAKE_CTX *ctx;\n\tBIO *bconn;\n\tBIO_puts(out, "Authenticating with JPAKE\\n");\n\tctx = jpake_init("server", "client", secret);\n\tbconn = BIO_new(BIO_f_buffer());\n\tBIO_push(bconn, conn);\n\tjpake_receive_step1(ctx, bconn);\n\tjpake_send_step1(bconn, ctx);\n\tjpake_receive_step2(ctx, bconn);\n\tjpake_send_step2(bconn, ctx);\n\tjpake_receive_step3a(ctx, bconn);\n\tjpake_send_step3b(bconn, ctx);\n\tBIO_puts(out, "JPAKE authentication succeeded\\n");\n\tBIO_pop(bconn);\n\tBIO_free(bconn);\n\t}', 'static JPAKE_CTX *jpake_init(const char *us, const char *them,\n\t\t\t\t\t\t\t const char *secret)\n\t{\n\tBIGNUM *p = NULL;\n\tBIGNUM *g = NULL;\n\tBIGNUM *q = NULL;\n\tBIGNUM *bnsecret = BN_new();\n\tJPAKE_CTX *ctx;\n\tBN_hex2bn(&p, "F9E5B365665EA7A05A9C534502780FEE6F1AB5BD4F49947FD036DBD7E905269AF46EF28B0FC07487EE4F5D20FB3C0AF8E700F3A2FA3414970CBED44FEDFF80CE78D800F184BB82435D137AADA2C6C16523247930A63B85661D1FC817A51ACD96168E95898A1F83A79FFB529368AA7833ABD1B0C3AEDDB14D2E1A2F71D99F763F");\n\tg = BN_new();\n\tBN_set_word(g, 2);\n\tq = BN_new();\n\tBN_rshift1(q, p);\n\tBN_bin2bn((const unsigned char *)secret, strlen(secret), bnsecret);\n\tctx = JPAKE_CTX_new(us, them, p, g, q, bnsecret);\n\tBN_free(bnsecret);\n\tBN_free(q);\n\tBN_free(g);\n\tBN_free(p);\n\treturn ctx;\n\t}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n\t{\n\tunsigned int i,m;\n\tunsigned int n;\n\tBN_ULONG l;\n\tBIGNUM *bn = NULL;\n\tif (ret == NULL)\n\t\tret = bn = BN_new();\n\tif (ret == NULL) return(NULL);\n\tbn_check_top(ret);\n\tl=0;\n\tn=len;\n\tif (n == 0)\n\t\t{\n\t\tret->top=0;\n\t\treturn(ret);\n\t\t}\n\ti=((n-1)/BN_BYTES)+1;\n\tm=((n-1)%(BN_BYTES));\n\tif (bn_wexpand(ret, (int)i) == NULL)\n\t\t{\n\t\tif (bn) BN_free(bn);\n\t\treturn NULL;\n\t\t}\n\tret->top=i;\n\tret->neg=0;\n\twhile (n--)\n\t\t{\n\t\tl=(l<<8L)| *(s++);\n\t\tif (m-- == 0)\n\t\t\t{\n\t\t\tret->d[--i]=l;\n\t\t\tl=0;\n\t\t\tm=BN_BYTES-1;\n\t\t\t}\n\t\t}\n\tbn_correct_top(ret);\n\treturn(ret);\n\t}']
34,829
0
https://github.com/openssl/openssl/blob/5dfc369ffcdc4722482c818e6ba6cf6e704c2cb5/crypto/rsa/rsa_oaep.c/#L66
int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen, unsigned char *from, int flen, unsigned char *param, int plen) { int i, emlen = tlen - 1; unsigned char *db, *seed; unsigned char *dbmask, seedmask[SHA_DIGEST_LENGTH]; if (flen > emlen - 2 * SHA_DIGEST_LENGTH - 1) { RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); return (0); } if (emlen < 2 * SHA_DIGEST_LENGTH + 1) { RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, RSA_R_KEY_SIZE_TOO_SMALL); return (0); } dbmask = Malloc(emlen - SHA_DIGEST_LENGTH); if (dbmask == NULL) { RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE); return (0); } to[0] = 0; seed = to + 1; db = to + SHA_DIGEST_LENGTH + 1; SHA1(param, plen, db); memset(db + SHA_DIGEST_LENGTH, 0, emlen - flen - 2 * SHA_DIGEST_LENGTH - 1); db[emlen - flen - SHA_DIGEST_LENGTH - 1] = 0x01; memcpy(db + emlen - flen - SHA_DIGEST_LENGTH, from, (unsigned int) flen); RAND_bytes(seed, SHA_DIGEST_LENGTH); #ifdef PKCS_TESTVECT memcpy(seed, "\xaa\xfd\x12\xf6\x59\xca\xe6\x34\x89\xb4\x79\xe5\x07\x6d\xde\xc2\xf0\x6c\xb5\x8f", 20); #endif MGF1(dbmask, emlen - SHA_DIGEST_LENGTH, seed, SHA_DIGEST_LENGTH); for (i = 0; i < emlen - SHA_DIGEST_LENGTH; i++) db[i] ^= dbmask[i]; MGF1(seedmask, SHA_DIGEST_LENGTH, db, emlen - SHA_DIGEST_LENGTH); for (i = 0; i < SHA_DIGEST_LENGTH; i++) seed[i] ^= seedmask[i]; Free(dbmask); return (1); }
['static int RSA_eay_public_encrypt(int flen, unsigned char *from,\n\t unsigned char *to, RSA *rsa, int padding)\n\t{\n\tBIGNUM f,ret;\n\tint i,j,k,num=0,r= -1;\n\tunsigned char *buf=NULL;\n\tBN_CTX *ctx=NULL;\n\tBN_init(&f);\n\tBN_init(&ret);\n\tif ((ctx=BN_CTX_new()) == NULL) goto err;\n\tnum=BN_num_bytes(rsa->n);\n\tif ((buf=(unsigned char *)Malloc(num)) == NULL)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tswitch (padding)\n\t\t{\n\tcase RSA_PKCS1_PADDING:\n\t\ti=RSA_padding_add_PKCS1_type_2(buf,num,from,flen);\n\t\tbreak;\n#ifndef NO_SHA\n\tcase RSA_PKCS1_OAEP_PADDING:\n\t i=RSA_padding_add_PKCS1_OAEP(buf,num,from,flen,NULL,0);\n\t\tbreak;\n#endif\n\tcase RSA_SSLV23_PADDING:\n\t\ti=RSA_padding_add_SSLv23(buf,num,from,flen);\n\t\tbreak;\n\tcase RSA_NO_PADDING:\n\t\ti=RSA_padding_add_none(buf,num,from,flen);\n\t\tbreak;\n\tdefault:\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,RSA_R_UNKNOWN_PADDING_TYPE);\n\t\tgoto err;\n\t\t}\n\tif (i <= 0) goto err;\n\tif (BN_bin2bn(buf,num,&f) == NULL) goto err;\n\tif ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC))\n\t\t{\n\t\tif ((rsa->_method_mod_n=BN_MONT_CTX_new()) != NULL)\n\t\t\tif (!BN_MONT_CTX_set(rsa->_method_mod_n,rsa->n,ctx))\n\t\t\t goto err;\n\t\t}\n\tif (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx,\n\t\trsa->_method_mod_n)) goto err;\n\tj=BN_num_bytes(&ret);\n\ti=BN_bn2bin(&ret,&(to[num-j]));\n\tfor (k=0; k<(num-i); k++)\n\t\tto[k]=0;\n\tr=num;\nerr:\n\tif (ctx != NULL) BN_CTX_free(ctx);\n\tBN_clear_free(&f);\n\tBN_clear_free(&ret);\n\tif (buf != NULL)\n\t\t{\n\t\tmemset(buf,0,num);\n\t\tFree(buf);\n\t\t}\n\treturn(r);\n\t}', 'int BN_num_bits(BIGNUM *a)\n\t{\n\tBN_ULONG l;\n\tint i;\n\tbn_check_top(a);\n\tif (a->top == 0) return(0);\n\tl=a->d[a->top-1];\n\ti=(a->top-1)*BN_BITS2;\n\tif (l == 0)\n\t\t{\n#if !defined(NO_STDIO) && !defined(WIN16)\n\t\tfprintf(stderr,"BAD TOP VALUE\\n");\n#endif\n\t\tabort();\n\t\t}\n\treturn(i+BN_num_bits_word(l));\n\t}', 'int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,\n\t unsigned char *from, int flen, unsigned char *param, int plen)\n {\n int i, emlen = tlen - 1;\n unsigned char *db, *seed;\n unsigned char *dbmask, seedmask[SHA_DIGEST_LENGTH];\n if (flen > emlen - 2 * SHA_DIGEST_LENGTH - 1)\n\t{\n\tRSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP,\n\t RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);\n\treturn (0);\n\t}\n if (emlen < 2 * SHA_DIGEST_LENGTH + 1)\n\t{\n\tRSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, RSA_R_KEY_SIZE_TOO_SMALL);\n\treturn (0);\n\t}\n dbmask = Malloc(emlen - SHA_DIGEST_LENGTH);\n if (dbmask == NULL)\n\t{\n\tRSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE);\n\treturn (0);\n\t}\n to[0] = 0;\n seed = to + 1;\n db = to + SHA_DIGEST_LENGTH + 1;\n SHA1(param, plen, db);\n memset(db + SHA_DIGEST_LENGTH, 0,\n\t emlen - flen - 2 * SHA_DIGEST_LENGTH - 1);\n db[emlen - flen - SHA_DIGEST_LENGTH - 1] = 0x01;\n memcpy(db + emlen - flen - SHA_DIGEST_LENGTH, from, (unsigned int) flen);\n RAND_bytes(seed, SHA_DIGEST_LENGTH);\n#ifdef PKCS_TESTVECT\n memcpy(seed,\n\t "\\xaa\\xfd\\x12\\xf6\\x59\\xca\\xe6\\x34\\x89\\xb4\\x79\\xe5\\x07\\x6d\\xde\\xc2\\xf0\\x6c\\xb5\\x8f",\n\t 20);\n#endif\n MGF1(dbmask, emlen - SHA_DIGEST_LENGTH, seed, SHA_DIGEST_LENGTH);\n for (i = 0; i < emlen - SHA_DIGEST_LENGTH; i++)\n\tdb[i] ^= dbmask[i];\n MGF1(seedmask, SHA_DIGEST_LENGTH, db, emlen - SHA_DIGEST_LENGTH);\n for (i = 0; i < SHA_DIGEST_LENGTH; i++)\n\tseed[i] ^= seedmask[i];\n Free(dbmask);\n return (1);\n }']
34,830
0
https://github.com/nginx/nginx/blob/e4ecddfdb0d2ffc872658e36028971ad9a873726/src/core/ngx_hash.c/#L980
ngx_int_t ngx_hash_add_key(ngx_hash_keys_arrays_t *ha, ngx_str_t *key, void *value, ngx_uint_t flags) { size_t len; u_char *p; ngx_str_t *name; ngx_uint_t i, k, n, skip, last; ngx_array_t *keys, *hwc; ngx_hash_key_t *hk; last = key->len; if (flags & NGX_HASH_WILDCARD_KEY) { n = 0; for (i = 0; i < key->len; i++) { if (key->data[i] == '*') { if (++n > 1) { return NGX_DECLINED; } } if (key->data[i] == '.' && key->data[i + 1] == '.') { return NGX_DECLINED; } } if (key->len > 1 && key->data[0] == '.') { skip = 1; goto wildcard; } if (key->len > 2) { if (key->data[0] == '*' && key->data[1] == '.') { skip = 2; goto wildcard; } if (key->data[i - 2] == '.' && key->data[i - 1] == '*') { skip = 0; last -= 2; goto wildcard; } } if (n) { return NGX_DECLINED; } } k = 0; for (i = 0; i < last; i++) { if (!(flags & NGX_HASH_READONLY_KEY)) { key->data[i] = ngx_tolower(key->data[i]); } k = ngx_hash(k, key->data[i]); } k %= ha->hsize; name = ha->keys_hash[k].elts; if (name) { for (i = 0; i < ha->keys_hash[k].nelts; i++) { if (last != name[i].len) { continue; } if (ngx_strncmp(key->data, name[i].data, last) == 0) { return NGX_BUSY; } } } else { if (ngx_array_init(&ha->keys_hash[k], ha->temp_pool, 4, sizeof(ngx_str_t)) != NGX_OK) { return NGX_ERROR; } } name = ngx_array_push(&ha->keys_hash[k]); if (name == NULL) { return NGX_ERROR; } *name = *key; hk = ngx_array_push(&ha->keys); if (hk == NULL) { return NGX_ERROR; } hk->key = *key; hk->key_hash = ngx_hash_key(key->data, last); hk->value = value; return NGX_OK; wildcard: k = ngx_hash_strlow(&key->data[skip], &key->data[skip], last - skip); k %= ha->hsize; if (skip == 1) { name = ha->keys_hash[k].elts; if (name) { len = last - skip; for (i = 0; i < ha->keys_hash[k].nelts; i++) { if (len != name[i].len) { continue; } if (ngx_strncmp(&key->data[1], name[i].data, len) == 0) { return NGX_BUSY; } } } else { if (ngx_array_init(&ha->keys_hash[k], ha->temp_pool, 4, sizeof(ngx_str_t)) != NGX_OK) { return NGX_ERROR; } } name = ngx_array_push(&ha->keys_hash[k]); if (name == NULL) { return NGX_ERROR; } name->len = last - 1; name->data = ngx_pnalloc(ha->temp_pool, name->len); if (name->data == NULL) { return NGX_ERROR; } ngx_memcpy(name->data, &key->data[1], name->len); } if (skip) { p = ngx_pnalloc(ha->temp_pool, last); if (p == NULL) { return NGX_ERROR; } len = 0; n = 0; for (i = last - 1; i; i--) { if (key->data[i] == '.') { ngx_memcpy(&p[n], &key->data[i + 1], len); n += len; p[n++] = '.'; len = 0; continue; } len++; } if (len) { ngx_memcpy(&p[n], &key->data[1], len); n += len; } p[n] = '\0'; hwc = &ha->dns_wc_head; keys = &ha->dns_wc_head_hash[k]; } else { last++; p = ngx_pnalloc(ha->temp_pool, last); if (p == NULL) { return NGX_ERROR; } ngx_cpystrn(p, key->data, last); hwc = &ha->dns_wc_tail; keys = &ha->dns_wc_tail_hash[k]; } hk = ngx_array_push(hwc); if (hk == NULL) { return NGX_ERROR; } hk->key.len = last - 1; hk->key.data = p; hk->key_hash = 0; hk->value = value; name = keys->elts; if (name) { len = last - skip; for (i = 0; i < keys->nelts; i++) { if (len != name[i].len) { continue; } if (ngx_strncmp(key->data + skip, name[i].data, len) == 0) { return NGX_BUSY; } } } else { if (ngx_array_init(keys, ha->temp_pool, 4, sizeof(ngx_str_t)) != NGX_OK) { return NGX_ERROR; } } name = ngx_array_push(keys); if (name == NULL) { return NGX_ERROR; } name->len = last - skip; name->data = ngx_pnalloc(ha->temp_pool, name->len); if (name->data == NULL) { return NGX_ERROR; } ngx_memcpy(name->data, key->data + skip, name->len); return NGX_OK; }
['static char *\nngx_http_map_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)\n{\n ngx_http_map_conf_t *mcf = conf;\n char *rv;\n ngx_str_t *value, name;\n ngx_conf_t save;\n ngx_pool_t *pool;\n ngx_hash_init_t hash;\n ngx_http_map_ctx_t *map;\n ngx_http_variable_t *var;\n ngx_http_map_conf_ctx_t ctx;\n if (mcf->hash_max_size == NGX_CONF_UNSET_UINT) {\n mcf->hash_max_size = 2048;\n }\n if (mcf->hash_bucket_size == NGX_CONF_UNSET_UINT) {\n mcf->hash_bucket_size = ngx_cacheline_size;\n } else {\n mcf->hash_bucket_size = ngx_align(mcf->hash_bucket_size,\n ngx_cacheline_size);\n }\n map = ngx_pcalloc(cf->pool, sizeof(ngx_http_map_ctx_t));\n if (map == NULL) {\n return NGX_CONF_ERROR;\n }\n value = cf->args->elts;\n name = value[1];\n name.len--;\n name.data++;\n map->index = ngx_http_get_variable_index(cf, &name);\n if (map->index == NGX_ERROR) {\n return NGX_CONF_ERROR;\n }\n name = value[2];\n name.len--;\n name.data++;\n var = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGEABLE);\n if (var == NULL) {\n return NGX_CONF_ERROR;\n }\n var->get_handler = ngx_http_map_variable;\n var->data = (uintptr_t) map;\n pool = ngx_create_pool(16384, cf->log);\n if (pool == NULL) {\n return NGX_CONF_ERROR;\n }\n ctx.keys.pool = cf->pool;\n ctx.keys.temp_pool = pool;\n if (ngx_hash_keys_array_init(&ctx.keys, NGX_HASH_LARGE) != NGX_OK) {\n ngx_destroy_pool(pool);\n return NGX_CONF_ERROR;\n }\n ctx.values_hash = ngx_pcalloc(pool, sizeof(ngx_array_t) * ctx.keys.hsize);\n if (ctx.values_hash == NULL) {\n ngx_destroy_pool(pool);\n return NGX_CONF_ERROR;\n }\n ctx.default_value = NULL;\n ctx.hostnames = 0;\n save = *cf;\n cf->pool = pool;\n cf->ctx = &ctx;\n cf->handler = ngx_http_map;\n cf->handler_conf = conf;\n rv = ngx_conf_parse(cf, NULL);\n *cf = save;\n if (rv != NGX_CONF_OK) {\n ngx_destroy_pool(pool);\n return rv;\n }\n map->default_value = ctx.default_value ? ctx.default_value:\n &ngx_http_variable_null_value;\n hash.key = ngx_hash_key_lc;\n hash.max_size = mcf->hash_max_size;\n hash.bucket_size = mcf->hash_bucket_size;\n hash.name = "map_hash";\n hash.pool = cf->pool;\n if (ctx.keys.keys.nelts) {\n hash.hash = &map->hash.hash;\n hash.temp_pool = NULL;\n if (ngx_hash_init(&hash, ctx.keys.keys.elts, ctx.keys.keys.nelts)\n != NGX_OK)\n {\n ngx_destroy_pool(pool);\n return NGX_CONF_ERROR;\n }\n }\n if (ctx.keys.dns_wc_head.nelts) {\n ngx_qsort(ctx.keys.dns_wc_head.elts,\n (size_t) ctx.keys.dns_wc_head.nelts,\n sizeof(ngx_hash_key_t), ngx_http_map_cmp_dns_wildcards);\n hash.hash = NULL;\n hash.temp_pool = pool;\n if (ngx_hash_wildcard_init(&hash, ctx.keys.dns_wc_head.elts,\n ctx.keys.dns_wc_head.nelts)\n != NGX_OK)\n {\n ngx_destroy_pool(pool);\n return NGX_CONF_ERROR;\n }\n map->hash.wc_head = (ngx_hash_wildcard_t *) hash.hash;\n }\n if (ctx.keys.dns_wc_tail.nelts) {\n ngx_qsort(ctx.keys.dns_wc_tail.elts,\n (size_t) ctx.keys.dns_wc_tail.nelts,\n sizeof(ngx_hash_key_t), ngx_http_map_cmp_dns_wildcards);\n hash.hash = NULL;\n hash.temp_pool = pool;\n if (ngx_hash_wildcard_init(&hash, ctx.keys.dns_wc_tail.elts,\n ctx.keys.dns_wc_tail.nelts)\n != NGX_OK)\n {\n ngx_destroy_pool(pool);\n return NGX_CONF_ERROR;\n }\n map->hash.wc_tail = (ngx_hash_wildcard_t *) hash.hash;\n }\n ngx_destroy_pool(pool);\n return rv;\n}', 'ngx_int_t\nngx_http_get_variable_index(ngx_conf_t *cf, ngx_str_t *name)\n{\n ngx_uint_t i;\n ngx_http_variable_t *v;\n ngx_http_core_main_conf_t *cmcf;\n cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);\n v = cmcf->variables.elts;\n if (v == NULL) {\n if (ngx_array_init(&cmcf->variables, cf->pool, 4,\n sizeof(ngx_http_variable_t))\n != NGX_OK)\n {\n return NGX_ERROR;\n }\n } else {\n for (i = 0; i < cmcf->variables.nelts; i++) {\n if (name->len != v[i].name.len\n || ngx_strncasecmp(name->data, v[i].name.data, name->len) != 0)\n {\n continue;\n }\n return i;\n }\n }\n v = ngx_array_push(&cmcf->variables);\n if (v == NULL) {\n return NGX_ERROR;\n }\n v->name.len = name->len;\n v->name.data = ngx_pnalloc(cf->pool, name->len);\n if (v->name.data == NULL) {\n return NGX_ERROR;\n }\n ngx_strlow(v->name.data, name->data, name->len);\n v->set_handler = NULL;\n v->get_handler = NULL;\n v->data = 0;\n v->flags = 0;\n v->index = cmcf->variables.nelts - 1;\n return cmcf->variables.nelts - 1;\n}', 'ngx_http_variable_t *\nngx_http_add_variable(ngx_conf_t *cf, ngx_str_t *name, ngx_uint_t flags)\n{\n ngx_int_t rc;\n ngx_uint_t i;\n ngx_hash_key_t *key;\n ngx_http_variable_t *v;\n ngx_http_core_main_conf_t *cmcf;\n cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);\n key = cmcf->variables_keys->keys.elts;\n for (i = 0; i < cmcf->variables_keys->keys.nelts; i++) {\n if (name->len != key[i].key.len\n || ngx_strncasecmp(name->data, key[i].key.data, name->len) != 0)\n {\n continue;\n }\n v = key[i].value;\n if (!(v->flags & NGX_HTTP_VAR_CHANGEABLE)) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "the duplicate \\"%V\\" variable", name);\n return NULL;\n }\n return v;\n }\n v = ngx_palloc(cf->pool, sizeof(ngx_http_variable_t));\n if (v == NULL) {\n return NULL;\n }\n v->name.len = name->len;\n v->name.data = ngx_pnalloc(cf->pool, name->len);\n if (v->name.data == NULL) {\n return NULL;\n }\n ngx_strlow(v->name.data, name->data, name->len);\n v->set_handler = NULL;\n v->get_handler = NULL;\n v->data = 0;\n v->flags = flags;\n v->index = 0;\n rc = ngx_hash_add_key(cmcf->variables_keys, &v->name, v, 0);\n if (rc == NGX_ERROR) {\n return NULL;\n }\n if (rc == NGX_BUSY) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "conflicting variable name \\"%V\\"", name);\n return NULL;\n }\n return v;\n}', "ngx_int_t\nngx_hash_add_key(ngx_hash_keys_arrays_t *ha, ngx_str_t *key, void *value,\n ngx_uint_t flags)\n{\n size_t len;\n u_char *p;\n ngx_str_t *name;\n ngx_uint_t i, k, n, skip, last;\n ngx_array_t *keys, *hwc;\n ngx_hash_key_t *hk;\n last = key->len;\n if (flags & NGX_HASH_WILDCARD_KEY) {\n n = 0;\n for (i = 0; i < key->len; i++) {\n if (key->data[i] == '*') {\n if (++n > 1) {\n return NGX_DECLINED;\n }\n }\n if (key->data[i] == '.' && key->data[i + 1] == '.') {\n return NGX_DECLINED;\n }\n }\n if (key->len > 1 && key->data[0] == '.') {\n skip = 1;\n goto wildcard;\n }\n if (key->len > 2) {\n if (key->data[0] == '*' && key->data[1] == '.') {\n skip = 2;\n goto wildcard;\n }\n if (key->data[i - 2] == '.' && key->data[i - 1] == '*') {\n skip = 0;\n last -= 2;\n goto wildcard;\n }\n }\n if (n) {\n return NGX_DECLINED;\n }\n }\n k = 0;\n for (i = 0; i < last; i++) {\n if (!(flags & NGX_HASH_READONLY_KEY)) {\n key->data[i] = ngx_tolower(key->data[i]);\n }\n k = ngx_hash(k, key->data[i]);\n }\n k %= ha->hsize;\n name = ha->keys_hash[k].elts;\n if (name) {\n for (i = 0; i < ha->keys_hash[k].nelts; i++) {\n if (last != name[i].len) {\n continue;\n }\n if (ngx_strncmp(key->data, name[i].data, last) == 0) {\n return NGX_BUSY;\n }\n }\n } else {\n if (ngx_array_init(&ha->keys_hash[k], ha->temp_pool, 4,\n sizeof(ngx_str_t))\n != NGX_OK)\n {\n return NGX_ERROR;\n }\n }\n name = ngx_array_push(&ha->keys_hash[k]);\n if (name == NULL) {\n return NGX_ERROR;\n }\n *name = *key;\n hk = ngx_array_push(&ha->keys);\n if (hk == NULL) {\n return NGX_ERROR;\n }\n hk->key = *key;\n hk->key_hash = ngx_hash_key(key->data, last);\n hk->value = value;\n return NGX_OK;\nwildcard:\n k = ngx_hash_strlow(&key->data[skip], &key->data[skip], last - skip);\n k %= ha->hsize;\n if (skip == 1) {\n name = ha->keys_hash[k].elts;\n if (name) {\n len = last - skip;\n for (i = 0; i < ha->keys_hash[k].nelts; i++) {\n if (len != name[i].len) {\n continue;\n }\n if (ngx_strncmp(&key->data[1], name[i].data, len) == 0) {\n return NGX_BUSY;\n }\n }\n } else {\n if (ngx_array_init(&ha->keys_hash[k], ha->temp_pool, 4,\n sizeof(ngx_str_t))\n != NGX_OK)\n {\n return NGX_ERROR;\n }\n }\n name = ngx_array_push(&ha->keys_hash[k]);\n if (name == NULL) {\n return NGX_ERROR;\n }\n name->len = last - 1;\n name->data = ngx_pnalloc(ha->temp_pool, name->len);\n if (name->data == NULL) {\n return NGX_ERROR;\n }\n ngx_memcpy(name->data, &key->data[1], name->len);\n }\n if (skip) {\n p = ngx_pnalloc(ha->temp_pool, last);\n if (p == NULL) {\n return NGX_ERROR;\n }\n len = 0;\n n = 0;\n for (i = last - 1; i; i--) {\n if (key->data[i] == '.') {\n ngx_memcpy(&p[n], &key->data[i + 1], len);\n n += len;\n p[n++] = '.';\n len = 0;\n continue;\n }\n len++;\n }\n if (len) {\n ngx_memcpy(&p[n], &key->data[1], len);\n n += len;\n }\n p[n] = '\\0';\n hwc = &ha->dns_wc_head;\n keys = &ha->dns_wc_head_hash[k];\n } else {\n last++;\n p = ngx_pnalloc(ha->temp_pool, last);\n if (p == NULL) {\n return NGX_ERROR;\n }\n ngx_cpystrn(p, key->data, last);\n hwc = &ha->dns_wc_tail;\n keys = &ha->dns_wc_tail_hash[k];\n }\n hk = ngx_array_push(hwc);\n if (hk == NULL) {\n return NGX_ERROR;\n }\n hk->key.len = last - 1;\n hk->key.data = p;\n hk->key_hash = 0;\n hk->value = value;\n name = keys->elts;\n if (name) {\n len = last - skip;\n for (i = 0; i < keys->nelts; i++) {\n if (len != name[i].len) {\n continue;\n }\n if (ngx_strncmp(key->data + skip, name[i].data, len) == 0) {\n return NGX_BUSY;\n }\n }\n } else {\n if (ngx_array_init(keys, ha->temp_pool, 4, sizeof(ngx_str_t)) != NGX_OK)\n {\n return NGX_ERROR;\n }\n }\n name = ngx_array_push(keys);\n if (name == NULL) {\n return NGX_ERROR;\n }\n name->len = last - skip;\n name->data = ngx_pnalloc(ha->temp_pool, name->len);\n if (name->data == NULL) {\n return NGX_ERROR;\n }\n ngx_memcpy(name->data, key->data + skip, name->len);\n return NGX_OK;\n}"]
34,831
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/ec/ec_lib.c/#L298
int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor) { if (generator == NULL) { ECerr(EC_F_EC_GROUP_SET_GENERATOR, ERR_R_PASSED_NULL_PARAMETER); return 0; } if (group->generator == NULL) { group->generator = EC_POINT_new(group); if (group->generator == NULL) return 0; } if (!EC_POINT_copy(group->generator, generator)) return 0; if (order != NULL) { if (!BN_copy(group->order, order)) return 0; } else BN_zero(group->order); if (cofactor != NULL) { if (!BN_copy(group->cofactor, cofactor)) return 0; } else BN_zero(group->cofactor); ec_precompute_mont_data(group); return 1; }
['int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator,\n const BIGNUM *order, const BIGNUM *cofactor)\n{\n if (generator == NULL) {\n ECerr(EC_F_EC_GROUP_SET_GENERATOR, ERR_R_PASSED_NULL_PARAMETER);\n return 0;\n }\n if (group->generator == NULL) {\n group->generator = EC_POINT_new(group);\n if (group->generator == NULL)\n return 0;\n }\n if (!EC_POINT_copy(group->generator, generator))\n return 0;\n if (order != NULL) {\n if (!BN_copy(group->order, order))\n return 0;\n } else\n BN_zero(group->order);\n if (cofactor != NULL) {\n if (!BN_copy(group->cofactor, cofactor))\n return 0;\n } else\n BN_zero(group->cofactor);\n ec_precompute_mont_data(group);\n return 1;\n}', 'EC_POINT *EC_POINT_new(const EC_GROUP *group)\n{\n EC_POINT *ret;\n if (group == NULL) {\n ECerr(EC_F_EC_POINT_NEW, ERR_R_PASSED_NULL_PARAMETER);\n return NULL;\n }\n if (group->meth->point_init == 0) {\n ECerr(EC_F_EC_POINT_NEW, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return NULL;\n }\n ret = OPENSSL_malloc(sizeof(*ret));\n if (ret == NULL) {\n ECerr(EC_F_EC_POINT_NEW, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n ret->meth = group->meth;\n if (!ret->meth->point_init(ret)) {\n OPENSSL_free(ret);\n return NULL;\n }\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifdef CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}', 'int EC_POINT_copy(EC_POINT *dest, const EC_POINT *src)\n{\n if (dest->meth->point_copy == 0) {\n ECerr(EC_F_EC_POINT_COPY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n if (dest->meth != src->meth) {\n ECerr(EC_F_EC_POINT_COPY, EC_R_INCOMPATIBLE_OBJECTS);\n return 0;\n }\n if (dest == src)\n return 1;\n return dest->meth->point_copy(dest, src);\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}']
34,832
0
https://github.com/openssl/openssl/blob/5b166395387e896d1c109ce3a4b2b55eb4cf9c02/apps/s_server.c/#L885
static int sv_body(char *hostname, int s, unsigned char *context) { char *buf=NULL; fd_set readfds; int ret=1,width; int k,i; unsigned long l; SSL *con=NULL; BIO *sbio; #ifdef OPENSSL_SYS_WINDOWS struct timeval tv; #endif if ((buf=OPENSSL_malloc(bufsize)) == NULL) { BIO_printf(bio_err,"out of memory\n"); goto err; } #ifdef FIONBIO if (s_nbio) { unsigned long sl=1; if (!s_quiet) BIO_printf(bio_err,"turning on non blocking io\n"); if (BIO_socket_ioctl(s,FIONBIO,&sl) < 0) ERR_print_errors(bio_err); } #endif if (con == NULL) { con=SSL_new(ctx); #ifndef OPENSSL_NO_KRB5 if ((con->kssl_ctx = kssl_ctx_new()) != NULL) { kssl_ctx_setstring(con->kssl_ctx, KSSL_SERVICE, KRB5SVC); kssl_ctx_setstring(con->kssl_ctx, KSSL_KEYTAB, KRB5KEYTAB); } #endif if(context) SSL_set_session_id_context(con, context, strlen((char *)context)); } SSL_clear(con); sbio=BIO_new_socket(s,BIO_NOCLOSE); if (s_nbio_test) { BIO *test; test=BIO_new(BIO_f_nbio_test()); sbio=BIO_push(test,sbio); } SSL_set_bio(con,sbio,sbio); SSL_set_accept_state(con); if (s_debug) { con->debug=1; BIO_set_callback(SSL_get_rbio(con),bio_dump_cb); BIO_set_callback_arg(SSL_get_rbio(con),bio_s_out); } width=s+1; for (;;) { int read_from_terminal; int read_from_sslcon; read_from_terminal = 0; read_from_sslcon = SSL_pending(con); if (!read_from_sslcon) { FD_ZERO(&readfds); #ifndef OPENSSL_SYS_WINDOWS FD_SET(fileno(stdin),&readfds); #endif FD_SET(s,&readfds); #ifdef OPENSSL_SYS_WINDOWS tv.tv_sec = 1; tv.tv_usec = 0; i=select(width,(void *)&readfds,NULL,NULL,&tv); if((i < 0) || (!i && !_kbhit() ) )continue; if(_kbhit()) read_from_terminal = 1; #else i=select(width,(void *)&readfds,NULL,NULL,NULL); if (i <= 0) continue; if (FD_ISSET(fileno(stdin),&readfds)) read_from_terminal = 1; #endif if (FD_ISSET(s,&readfds)) read_from_sslcon = 1; } if (read_from_terminal) { if (s_crlf) { int j, lf_num; i=read(fileno(stdin), buf, bufsize/2); lf_num = 0; for (j = 0; j < i; j++) if (buf[j] == '\n') lf_num++; for (j = i-1; j >= 0; j--) { buf[j+lf_num] = buf[j]; if (buf[j] == '\n') { lf_num--; i++; buf[j+lf_num] = '\r'; } } assert(lf_num == 0); } else i=read(fileno(stdin),buf,bufsize); if (!s_quiet) { if ((i <= 0) || (buf[0] == 'Q')) { BIO_printf(bio_s_out,"DONE\n"); SHUTDOWN(s); close_accept_socket(); ret= -11; goto err; } if ((i <= 0) || (buf[0] == 'q')) { BIO_printf(bio_s_out,"DONE\n"); SHUTDOWN(s); goto err; } if ((buf[0] == 'r') && ((buf[1] == '\n') || (buf[1] == '\r'))) { SSL_renegotiate(con); i=SSL_do_handshake(con); printf("SSL_do_handshake -> %d\n",i); i=0; continue; } if ((buf[0] == 'R') && ((buf[1] == '\n') || (buf[1] == '\r'))) { SSL_set_verify(con, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,NULL); SSL_renegotiate(con); i=SSL_do_handshake(con); printf("SSL_do_handshake -> %d\n",i); i=0; continue; } if (buf[0] == 'P') { static char *str="Lets print some clear text\n"; BIO_write(SSL_get_wbio(con),str,strlen(str)); } if (buf[0] == 'S') { print_stats(bio_s_out,SSL_get_SSL_CTX(con)); } } #ifdef CHARSET_EBCDIC ebcdic2ascii(buf,buf,i); #endif l=k=0; for (;;) { #ifdef RENEG { static count=0; if (++count == 100) { count=0; SSL_renegotiate(con); } } #endif k=SSL_write(con,&(buf[l]),(unsigned int)i); switch (SSL_get_error(con,k)) { case SSL_ERROR_NONE: break; case SSL_ERROR_WANT_WRITE: case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_X509_LOOKUP: BIO_printf(bio_s_out,"Write BLOCK\n"); break; case SSL_ERROR_SYSCALL: case SSL_ERROR_SSL: BIO_printf(bio_s_out,"ERROR\n"); ERR_print_errors(bio_err); ret=1; goto err; case SSL_ERROR_ZERO_RETURN: BIO_printf(bio_s_out,"DONE\n"); ret=1; goto err; } l+=k; i-=k; if (i <= 0) break; } } if (read_from_sslcon) { if (!SSL_is_init_finished(con)) { i=init_ssl_connection(con); if (i < 0) { ret=0; goto err; } else if (i == 0) { ret=1; goto err; } } else { again: i=SSL_read(con,(char *)buf,bufsize); switch (SSL_get_error(con,i)) { case SSL_ERROR_NONE: #ifdef CHARSET_EBCDIC ascii2ebcdic(buf,buf,i); #endif write(fileno(stdout),buf, (unsigned int)i); if (SSL_pending(con)) goto again; break; case SSL_ERROR_WANT_WRITE: case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_X509_LOOKUP: BIO_printf(bio_s_out,"Read BLOCK\n"); break; case SSL_ERROR_SYSCALL: case SSL_ERROR_SSL: BIO_printf(bio_s_out,"ERROR\n"); ERR_print_errors(bio_err); ret=1; goto err; case SSL_ERROR_ZERO_RETURN: BIO_printf(bio_s_out,"DONE\n"); ret=1; goto err; } } } } err: BIO_printf(bio_s_out,"shutting down SSL\n"); #if 1 SSL_set_shutdown(con,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN); #else SSL_shutdown(con); #endif if (con != NULL) SSL_free(con); BIO_printf(bio_s_out,"CONNECTION CLOSED\n"); if (buf != NULL) { memset(buf,0,bufsize); OPENSSL_free(buf); } if (ret >= 0) BIO_printf(bio_s_out,"ACCEPT\n"); return(ret); }
['static int sv_body(char *hostname, int s, unsigned char *context)\n\t{\n\tchar *buf=NULL;\n\tfd_set readfds;\n\tint ret=1,width;\n\tint k,i;\n\tunsigned long l;\n\tSSL *con=NULL;\n\tBIO *sbio;\n#ifdef OPENSSL_SYS_WINDOWS\n\tstruct timeval tv;\n#endif\n\tif ((buf=OPENSSL_malloc(bufsize)) == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"out of memory\\n");\n\t\tgoto err;\n\t\t}\n#ifdef FIONBIO\n\tif (s_nbio)\n\t\t{\n\t\tunsigned long sl=1;\n\t\tif (!s_quiet)\n\t\t\tBIO_printf(bio_err,"turning on non blocking io\\n");\n\t\tif (BIO_socket_ioctl(s,FIONBIO,&sl) < 0)\n\t\t\tERR_print_errors(bio_err);\n\t\t}\n#endif\n\tif (con == NULL) {\n\t\tcon=SSL_new(ctx);\n#ifndef OPENSSL_NO_KRB5\n\t\tif ((con->kssl_ctx = kssl_ctx_new()) != NULL)\n {\n kssl_ctx_setstring(con->kssl_ctx, KSSL_SERVICE,\n\t\t\t\t\t\t\t\tKRB5SVC);\n kssl_ctx_setstring(con->kssl_ctx, KSSL_KEYTAB,\n\t\t\t\t\t\t\t\tKRB5KEYTAB);\n }\n#endif\n\t\tif(context)\n\t\t SSL_set_session_id_context(con, context,\n\t\t\t\t\t\t strlen((char *)context));\n\t}\n\tSSL_clear(con);\n\tsbio=BIO_new_socket(s,BIO_NOCLOSE);\n\tif (s_nbio_test)\n\t\t{\n\t\tBIO *test;\n\t\ttest=BIO_new(BIO_f_nbio_test());\n\t\tsbio=BIO_push(test,sbio);\n\t\t}\n\tSSL_set_bio(con,sbio,sbio);\n\tSSL_set_accept_state(con);\n\tif (s_debug)\n\t\t{\n\t\tcon->debug=1;\n\t\tBIO_set_callback(SSL_get_rbio(con),bio_dump_cb);\n\t\tBIO_set_callback_arg(SSL_get_rbio(con),bio_s_out);\n\t\t}\n\twidth=s+1;\n\tfor (;;)\n\t\t{\n\t\tint read_from_terminal;\n\t\tint read_from_sslcon;\n\t\tread_from_terminal = 0;\n\t\tread_from_sslcon = SSL_pending(con);\n\t\tif (!read_from_sslcon)\n\t\t\t{\n\t\t\tFD_ZERO(&readfds);\n#ifndef OPENSSL_SYS_WINDOWS\n\t\t\tFD_SET(fileno(stdin),&readfds);\n#endif\n\t\t\tFD_SET(s,&readfds);\n#ifdef OPENSSL_SYS_WINDOWS\n\t\t\ttv.tv_sec = 1;\n\t\t\ttv.tv_usec = 0;\n\t\t\ti=select(width,(void *)&readfds,NULL,NULL,&tv);\n\t\t\tif((i < 0) || (!i && !_kbhit() ) )continue;\n\t\t\tif(_kbhit())\n\t\t\t\tread_from_terminal = 1;\n#else\n\t\t\ti=select(width,(void *)&readfds,NULL,NULL,NULL);\n\t\t\tif (i <= 0) continue;\n\t\t\tif (FD_ISSET(fileno(stdin),&readfds))\n\t\t\t\tread_from_terminal = 1;\n#endif\n\t\t\tif (FD_ISSET(s,&readfds))\n\t\t\t\tread_from_sslcon = 1;\n\t\t\t}\n\t\tif (read_from_terminal)\n\t\t\t{\n\t\t\tif (s_crlf)\n\t\t\t\t{\n\t\t\t\tint j, lf_num;\n\t\t\t\ti=read(fileno(stdin), buf, bufsize/2);\n\t\t\t\tlf_num = 0;\n\t\t\t\tfor (j = 0; j < i; j++)\n\t\t\t\t\tif (buf[j] == \'\\n\')\n\t\t\t\t\t\tlf_num++;\n\t\t\t\tfor (j = i-1; j >= 0; j--)\n\t\t\t\t\t{\n\t\t\t\t\tbuf[j+lf_num] = buf[j];\n\t\t\t\t\tif (buf[j] == \'\\n\')\n\t\t\t\t\t\t{\n\t\t\t\t\t\tlf_num--;\n\t\t\t\t\t\ti++;\n\t\t\t\t\t\tbuf[j+lf_num] = \'\\r\';\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\tassert(lf_num == 0);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\ti=read(fileno(stdin),buf,bufsize);\n\t\t\tif (!s_quiet)\n\t\t\t\t{\n\t\t\t\tif ((i <= 0) || (buf[0] == \'Q\'))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_s_out,"DONE\\n");\n\t\t\t\t\tSHUTDOWN(s);\n\t\t\t\t\tclose_accept_socket();\n\t\t\t\t\tret= -11;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\tif ((i <= 0) || (buf[0] == \'q\'))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_s_out,"DONE\\n");\n\t\t\t\t\tSHUTDOWN(s);\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\tif ((buf[0] == \'r\') &&\n\t\t\t\t\t((buf[1] == \'\\n\') || (buf[1] == \'\\r\')))\n\t\t\t\t\t{\n\t\t\t\t\tSSL_renegotiate(con);\n\t\t\t\t\ti=SSL_do_handshake(con);\n\t\t\t\t\tprintf("SSL_do_handshake -> %d\\n",i);\n\t\t\t\t\ti=0;\n\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\tif ((buf[0] == \'R\') &&\n\t\t\t\t\t((buf[1] == \'\\n\') || (buf[1] == \'\\r\')))\n\t\t\t\t\t{\n\t\t\t\t\tSSL_set_verify(con,\n\t\t\t\t\t\tSSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,NULL);\n\t\t\t\t\tSSL_renegotiate(con);\n\t\t\t\t\ti=SSL_do_handshake(con);\n\t\t\t\t\tprintf("SSL_do_handshake -> %d\\n",i);\n\t\t\t\t\ti=0;\n\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\tif (buf[0] == \'P\')\n\t\t\t\t\t{\n\t\t\t\t\tstatic char *str="Lets print some clear text\\n";\n\t\t\t\t\tBIO_write(SSL_get_wbio(con),str,strlen(str));\n\t\t\t\t\t}\n\t\t\t\tif (buf[0] == \'S\')\n\t\t\t\t\t{\n\t\t\t\t\tprint_stats(bio_s_out,SSL_get_SSL_CTX(con));\n\t\t\t\t\t}\n\t\t\t\t}\n#ifdef CHARSET_EBCDIC\n\t\t\tebcdic2ascii(buf,buf,i);\n#endif\n\t\t\tl=k=0;\n\t\t\tfor (;;)\n\t\t\t\t{\n#ifdef RENEG\n{ static count=0; if (++count == 100) { count=0; SSL_renegotiate(con); } }\n#endif\n\t\t\t\tk=SSL_write(con,&(buf[l]),(unsigned int)i);\n\t\t\t\tswitch (SSL_get_error(con,k))\n\t\t\t\t\t{\n\t\t\t\tcase SSL_ERROR_NONE:\n\t\t\t\t\tbreak;\n\t\t\t\tcase SSL_ERROR_WANT_WRITE:\n\t\t\t\tcase SSL_ERROR_WANT_READ:\n\t\t\t\tcase SSL_ERROR_WANT_X509_LOOKUP:\n\t\t\t\t\tBIO_printf(bio_s_out,"Write BLOCK\\n");\n\t\t\t\t\tbreak;\n\t\t\t\tcase SSL_ERROR_SYSCALL:\n\t\t\t\tcase SSL_ERROR_SSL:\n\t\t\t\t\tBIO_printf(bio_s_out,"ERROR\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\tcase SSL_ERROR_ZERO_RETURN:\n\t\t\t\t\tBIO_printf(bio_s_out,"DONE\\n");\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\tl+=k;\n\t\t\t\ti-=k;\n\t\t\t\tif (i <= 0) break;\n\t\t\t\t}\n\t\t\t}\n\t\tif (read_from_sslcon)\n\t\t\t{\n\t\t\tif (!SSL_is_init_finished(con))\n\t\t\t\t{\n\t\t\t\ti=init_ssl_connection(con);\n\t\t\t\tif (i < 0)\n\t\t\t\t\t{\n\t\t\t\t\tret=0;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\telse if (i == 0)\n\t\t\t\t\t{\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\nagain:\n\t\t\t\ti=SSL_read(con,(char *)buf,bufsize);\n\t\t\t\tswitch (SSL_get_error(con,i))\n\t\t\t\t\t{\n\t\t\t\tcase SSL_ERROR_NONE:\n#ifdef CHARSET_EBCDIC\n\t\t\t\t\tascii2ebcdic(buf,buf,i);\n#endif\n\t\t\t\t\twrite(fileno(stdout),buf,\n\t\t\t\t\t\t(unsigned int)i);\n\t\t\t\t\tif (SSL_pending(con)) goto again;\n\t\t\t\t\tbreak;\n\t\t\t\tcase SSL_ERROR_WANT_WRITE:\n\t\t\t\tcase SSL_ERROR_WANT_READ:\n\t\t\t\tcase SSL_ERROR_WANT_X509_LOOKUP:\n\t\t\t\t\tBIO_printf(bio_s_out,"Read BLOCK\\n");\n\t\t\t\t\tbreak;\n\t\t\t\tcase SSL_ERROR_SYSCALL:\n\t\t\t\tcase SSL_ERROR_SSL:\n\t\t\t\t\tBIO_printf(bio_s_out,"ERROR\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\tcase SSL_ERROR_ZERO_RETURN:\n\t\t\t\t\tBIO_printf(bio_s_out,"DONE\\n");\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\nerr:\n\tBIO_printf(bio_s_out,"shutting down SSL\\n");\n#if 1\n\tSSL_set_shutdown(con,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);\n#else\n\tSSL_shutdown(con);\n#endif\n\tif (con != NULL) SSL_free(con);\n\tBIO_printf(bio_s_out,"CONNECTION CLOSED\\n");\n\tif (buf != NULL)\n\t\t{\n\t\tmemset(buf,0,bufsize);\n\t\tOPENSSL_free(buf);\n\t\t}\n\tif (ret >= 0)\n\t\tBIO_printf(bio_s_out,"ACCEPT\\n");\n\treturn(ret);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n\treturn ret;\n\t}', 'SSL *SSL_new(SSL_CTX *ctx)\n\t{\n\tSSL *s;\n\tif (ctx == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_NEW,SSL_R_NULL_SSL_CTX);\n\t\treturn(NULL);\n\t\t}\n\tif (ctx->method == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_NEW,SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n\t\treturn(NULL);\n\t\t}\n\ts=(SSL *)OPENSSL_malloc(sizeof(SSL));\n\tif (s == NULL) goto err;\n\tmemset(s,0,sizeof(SSL));\n#ifndef\tOPENSSL_NO_KRB5\n\ts->kssl_ctx = kssl_ctx_new();\n#endif\n\tif (ctx->cert != NULL)\n\t\t{\n\t\ts->cert = ssl_cert_dup(ctx->cert);\n\t\tif (s->cert == NULL)\n\t\t\tgoto err;\n\t\t}\n\telse\n\t\ts->cert=NULL;\n\ts->sid_ctx_length=ctx->sid_ctx_length;\n\tmemcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx));\n\ts->verify_mode=ctx->verify_mode;\n\ts->verify_depth=ctx->verify_depth;\n\ts->verify_callback=ctx->default_verify_callback;\n\ts->generate_session_id=ctx->generate_session_id;\n\ts->purpose = ctx->purpose;\n\ts->trust = ctx->trust;\n\tCRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);\n\ts->ctx=ctx;\n\ts->verify_result=X509_V_OK;\n\ts->method=ctx->method;\n\tif (!s->method->ssl_new(s))\n\t\tgoto err;\n\ts->quiet_shutdown=ctx->quiet_shutdown;\n\ts->references=1;\n\ts->server=(ctx->method->ssl_accept == ssl_undefined_function)?0:1;\n\ts->options=ctx->options;\n\ts->mode=ctx->mode;\n\ts->read_ahead=ctx->read_ahead;\n\tSSL_clear(s);\n\tCRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n\treturn(s);\nerr:\n\tif (s != NULL)\n\t\t{\n\t\tif (s->cert != NULL)\n\t\t\tssl_cert_free(s->cert);\n\t\tif (s->ctx != NULL)\n\t\t\tSSL_CTX_free(s->ctx);\n\t\tOPENSSL_free(s);\n\t\t}\n\tSSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE);\n\treturn(NULL);\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}', 'int SSL_set_session_id_context(SSL *ssl,const unsigned char *sid_ctx,\n\t\t\t unsigned int sid_ctx_len)\n {\n if(sid_ctx_len > SSL_MAX_SID_CTX_LENGTH)\n\t{\n\tSSLerr(SSL_F_SSL_SET_SESSION_ID_CONTEXT,SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG);\n\treturn 0;\n\t}\n ssl->sid_ctx_length=sid_ctx_len;\n memcpy(ssl->sid_ctx,sid_ctx,sid_ctx_len);\n return 1;\n }', 'BIO *BIO_new_socket(int fd, int close_flag)\n\t{\n\tBIO *ret;\n\tret=BIO_new(BIO_s_socket());\n\tif (ret == NULL) return(NULL);\n\tBIO_set_fd(ret,fd,close_flag);\n\treturn(ret);\n\t}', 'BIO_METHOD *BIO_s_socket(void)\n\t{\n\treturn(&methods_sockp);\n\t}', 'BIO *BIO_new(BIO_METHOD *method)\n\t{\n\tBIO *ret=NULL;\n\tret=(BIO *)OPENSSL_malloc(sizeof(BIO));\n\tif (ret == NULL)\n\t\t{\n\t\tBIOerr(BIO_F_BIO_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tif (!BIO_set(ret,method))\n\t\t{\n\t\tOPENSSL_free(ret);\n\t\tret=NULL;\n\t\t}\n\treturn(ret);\n\t}', 'BIO_METHOD *BIO_f_nbio_test(void)\n\t{\n\treturn(&methods_nbiof);\n\t}', 'BIO *BIO_push(BIO *b, BIO *bio)\n\t{\n\tBIO *lb;\n\tif (b == NULL) return(bio);\n\tlb=b;\n\twhile (lb->next_bio != NULL)\n\t\tlb=lb->next_bio;\n\tlb->next_bio=bio;\n\tif (bio != NULL)\n\t\tbio->prev_bio=lb;\n\tBIO_ctrl(b,BIO_CTRL_PUSH,0,NULL);\n\treturn(b);\n\t}', 'void SSL_set_bio(SSL *s,BIO *rbio,BIO *wbio)\n\t{\n\tif (s->bbio != NULL)\n\t\t{\n\t\tif (s->wbio == s->bbio)\n\t\t\t{\n\t\t\ts->wbio=s->wbio->next_bio;\n\t\t\ts->bbio->next_bio=NULL;\n\t\t\t}\n\t\t}\n\tif ((s->rbio != NULL) && (s->rbio != rbio))\n\t\tBIO_free_all(s->rbio);\n\tif ((s->wbio != NULL) && (s->wbio != wbio) && (s->rbio != s->wbio))\n\t\tBIO_free_all(s->wbio);\n\ts->rbio=rbio;\n\ts->wbio=wbio;\n\t}']
34,833
0
https://github.com/libav/libav/blob/12b812d2e5dcc7c80b19b7c01713be31389120d5/libavcodec/mpegvideo_enc.c/#L1997
static av_always_inline void encode_mb_internal(MpegEncContext *s, int motion_x, int motion_y, int mb_block_height, int mb_block_count) { int16_t weight[8][64]; DCTELEM orig[8][64]; const int mb_x = s->mb_x; const int mb_y = s->mb_y; int i; int skip_dct[8]; int dct_offset = s->linesize * 8; uint8_t *ptr_y, *ptr_cb, *ptr_cr; int wrap_y, wrap_c; for (i = 0; i < mb_block_count; i++) skip_dct[i] = s->skipdct; if (s->adaptive_quant) { const int last_qp = s->qscale; const int mb_xy = mb_x + mb_y * s->mb_stride; s->lambda = s->lambda_table[mb_xy]; update_qscale(s); if (!(s->mpv_flags & FF_MPV_FLAG_QP_RD)) { s->qscale = s->current_picture_ptr->f.qscale_table[mb_xy]; s->dquant = s->qscale - last_qp; if (s->out_format == FMT_H263) { s->dquant = av_clip(s->dquant, -2, 2); if (s->codec_id == CODEC_ID_MPEG4) { if (!s->mb_intra) { if (s->pict_type == AV_PICTURE_TYPE_B) { if (s->dquant & 1 || s->mv_dir & MV_DIRECT) s->dquant = 0; } if (s->mv_type == MV_TYPE_8X8) s->dquant = 0; } } } } ff_set_qscale(s, last_qp + s->dquant); } else if (s->mpv_flags & FF_MPV_FLAG_QP_RD) ff_set_qscale(s, s->qscale + s->dquant); wrap_y = s->linesize; wrap_c = s->uvlinesize; ptr_y = s->new_picture.f.data[0] + (mb_y * 16 * wrap_y) + mb_x * 16; ptr_cb = s->new_picture.f.data[1] + (mb_y * mb_block_height * wrap_c) + mb_x * 8; ptr_cr = s->new_picture.f.data[2] + (mb_y * mb_block_height * wrap_c) + mb_x * 8; if (mb_x * 16 + 16 > s->width || mb_y * 16 + 16 > s->height) { uint8_t *ebuf = s->edge_emu_buffer + 32; s->dsp.emulated_edge_mc(ebuf, ptr_y, wrap_y, 16, 16, mb_x * 16, mb_y * 16, s->width, s->height); ptr_y = ebuf; s->dsp.emulated_edge_mc(ebuf + 18 * wrap_y, ptr_cb, wrap_c, 8, mb_block_height, mb_x * 8, mb_y * 8, s->width >> 1, s->height >> 1); ptr_cb = ebuf + 18 * wrap_y; s->dsp.emulated_edge_mc(ebuf + 18 * wrap_y + 8, ptr_cr, wrap_c, 8, mb_block_height, mb_x * 8, mb_y * 8, s->width >> 1, s->height >> 1); ptr_cr = ebuf + 18 * wrap_y + 8; } if (s->mb_intra) { if (s->flags & CODEC_FLAG_INTERLACED_DCT) { int progressive_score, interlaced_score; s->interlaced_dct = 0; progressive_score = s->dsp.ildct_cmp[4](s, ptr_y, NULL, wrap_y, 8) + s->dsp.ildct_cmp[4](s, ptr_y + wrap_y * 8, NULL, wrap_y, 8) - 400; if (progressive_score > 0) { interlaced_score = s->dsp.ildct_cmp[4](s, ptr_y, NULL, wrap_y * 2, 8) + s->dsp.ildct_cmp[4](s, ptr_y + wrap_y, NULL, wrap_y * 2, 8); if (progressive_score > interlaced_score) { s->interlaced_dct = 1; dct_offset = wrap_y; wrap_y <<= 1; if (s->chroma_format == CHROMA_422) wrap_c <<= 1; } } } s->dsp.get_pixels(s->block[0], ptr_y , wrap_y); s->dsp.get_pixels(s->block[1], ptr_y + 8 , wrap_y); s->dsp.get_pixels(s->block[2], ptr_y + dct_offset , wrap_y); s->dsp.get_pixels(s->block[3], ptr_y + dct_offset + 8 , wrap_y); if (s->flags & CODEC_FLAG_GRAY) { skip_dct[4] = 1; skip_dct[5] = 1; } else { s->dsp.get_pixels(s->block[4], ptr_cb, wrap_c); s->dsp.get_pixels(s->block[5], ptr_cr, wrap_c); if (!s->chroma_y_shift) { s->dsp.get_pixels(s->block[6], ptr_cb + (dct_offset >> 1), wrap_c); s->dsp.get_pixels(s->block[7], ptr_cr + (dct_offset >> 1), wrap_c); } } } else { op_pixels_func (*op_pix)[4]; qpel_mc_func (*op_qpix)[16]; uint8_t *dest_y, *dest_cb, *dest_cr; dest_y = s->dest[0]; dest_cb = s->dest[1]; dest_cr = s->dest[2]; if ((!s->no_rounding) || s->pict_type == AV_PICTURE_TYPE_B) { op_pix = s->dsp.put_pixels_tab; op_qpix = s->dsp.put_qpel_pixels_tab; } else { op_pix = s->dsp.put_no_rnd_pixels_tab; op_qpix = s->dsp.put_no_rnd_qpel_pixels_tab; } if (s->mv_dir & MV_DIR_FORWARD) { MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f.data, op_pix, op_qpix); op_pix = s->dsp.avg_pixels_tab; op_qpix = s->dsp.avg_qpel_pixels_tab; } if (s->mv_dir & MV_DIR_BACKWARD) { MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f.data, op_pix, op_qpix); } if (s->flags & CODEC_FLAG_INTERLACED_DCT) { int progressive_score, interlaced_score; s->interlaced_dct = 0; progressive_score = s->dsp.ildct_cmp[0](s, dest_y, ptr_y, wrap_y, 8) + s->dsp.ildct_cmp[0](s, dest_y + wrap_y * 8, ptr_y + wrap_y * 8, wrap_y, 8) - 400; if (s->avctx->ildct_cmp == FF_CMP_VSSE) progressive_score -= 400; if (progressive_score > 0) { interlaced_score = s->dsp.ildct_cmp[0](s, dest_y, ptr_y, wrap_y * 2, 8) + s->dsp.ildct_cmp[0](s, dest_y + wrap_y, ptr_y + wrap_y, wrap_y * 2, 8); if (progressive_score > interlaced_score) { s->interlaced_dct = 1; dct_offset = wrap_y; wrap_y <<= 1; if (s->chroma_format == CHROMA_422) wrap_c <<= 1; } } } s->dsp.diff_pixels(s->block[0], ptr_y, dest_y, wrap_y); s->dsp.diff_pixels(s->block[1], ptr_y + 8, dest_y + 8, wrap_y); s->dsp.diff_pixels(s->block[2], ptr_y + dct_offset, dest_y + dct_offset, wrap_y); s->dsp.diff_pixels(s->block[3], ptr_y + dct_offset + 8, dest_y + dct_offset + 8, wrap_y); if (s->flags & CODEC_FLAG_GRAY) { skip_dct[4] = 1; skip_dct[5] = 1; } else { s->dsp.diff_pixels(s->block[4], ptr_cb, dest_cb, wrap_c); s->dsp.diff_pixels(s->block[5], ptr_cr, dest_cr, wrap_c); if (!s->chroma_y_shift) { s->dsp.diff_pixels(s->block[6], ptr_cb + (dct_offset >> 1), dest_cb + (dct_offset >> 1), wrap_c); s->dsp.diff_pixels(s->block[7], ptr_cr + (dct_offset >> 1), dest_cr + (dct_offset >> 1), wrap_c); } } if (s->current_picture.mc_mb_var[s->mb_stride * mb_y + mb_x] < 2 * s->qscale * s->qscale) { if (s->dsp.sad[1](NULL, ptr_y , dest_y, wrap_y, 8) < 20 * s->qscale) skip_dct[0] = 1; if (s->dsp.sad[1](NULL, ptr_y + 8, dest_y + 8, wrap_y, 8) < 20 * s->qscale) skip_dct[1] = 1; if (s->dsp.sad[1](NULL, ptr_y + dct_offset, dest_y + dct_offset, wrap_y, 8) < 20 * s->qscale) skip_dct[2] = 1; if (s->dsp.sad[1](NULL, ptr_y + dct_offset + 8, dest_y + dct_offset + 8, wrap_y, 8) < 20 * s->qscale) skip_dct[3] = 1; if (s->dsp.sad[1](NULL, ptr_cb, dest_cb, wrap_c, 8) < 20 * s->qscale) skip_dct[4] = 1; if (s->dsp.sad[1](NULL, ptr_cr, dest_cr, wrap_c, 8) < 20 * s->qscale) skip_dct[5] = 1; if (!s->chroma_y_shift) { if (s->dsp.sad[1](NULL, ptr_cb + (dct_offset >> 1), dest_cb + (dct_offset >> 1), wrap_c, 8) < 20 * s->qscale) skip_dct[6] = 1; if (s->dsp.sad[1](NULL, ptr_cr + (dct_offset >> 1), dest_cr + (dct_offset >> 1), wrap_c, 8) < 20 * s->qscale) skip_dct[7] = 1; } } } if (s->quantizer_noise_shaping) { if (!skip_dct[0]) get_visual_weight(weight[0], ptr_y , wrap_y); if (!skip_dct[1]) get_visual_weight(weight[1], ptr_y + 8, wrap_y); if (!skip_dct[2]) get_visual_weight(weight[2], ptr_y + dct_offset , wrap_y); if (!skip_dct[3]) get_visual_weight(weight[3], ptr_y + dct_offset + 8, wrap_y); if (!skip_dct[4]) get_visual_weight(weight[4], ptr_cb , wrap_c); if (!skip_dct[5]) get_visual_weight(weight[5], ptr_cr , wrap_c); if (!s->chroma_y_shift) { if (!skip_dct[6]) get_visual_weight(weight[6], ptr_cb + (dct_offset >> 1), wrap_c); if (!skip_dct[7]) get_visual_weight(weight[7], ptr_cr + (dct_offset >> 1), wrap_c); } memcpy(orig[0], s->block[0], sizeof(DCTELEM) * 64 * mb_block_count); } assert(s->out_format != FMT_MJPEG || s->qscale == 8); { for (i = 0; i < mb_block_count; i++) { if (!skip_dct[i]) { int overflow; s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, s->qscale, &overflow); if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]); } else s->block_last_index[i] = -1; } if (s->quantizer_noise_shaping) { for (i = 0; i < mb_block_count; i++) { if (!skip_dct[i]) { s->block_last_index[i] = dct_quantize_refine(s, s->block[i], weight[i], orig[i], i, s->qscale); } } } if (s->luma_elim_threshold && !s->mb_intra) for (i = 0; i < 4; i++) dct_single_coeff_elimination(s, i, s->luma_elim_threshold); if (s->chroma_elim_threshold && !s->mb_intra) for (i = 4; i < mb_block_count; i++) dct_single_coeff_elimination(s, i, s->chroma_elim_threshold); if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) { for (i = 0; i < mb_block_count; i++) { if (s->block_last_index[i] == -1) s->coded_score[i] = INT_MAX / 256; } } } if ((s->flags & CODEC_FLAG_GRAY) && s->mb_intra) { s->block_last_index[4] = s->block_last_index[5] = 0; s->block[4][0] = s->block[5][0] = (1024 + s->c_dc_scale / 2) / s->c_dc_scale; } if (s->alternate_scan && s->dct_quantize != ff_dct_quantize_c) { for (i = 0; i < mb_block_count; i++) { int j; if (s->block_last_index[i] > 0) { for (j = 63; j > 0; j--) { if (s->block[i][s->intra_scantable.permutated[j]]) break; } s->block_last_index[i] = j; } } } switch(s->codec_id){ case CODEC_ID_MPEG1VIDEO: case CODEC_ID_MPEG2VIDEO: if (CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER) ff_mpeg1_encode_mb(s, s->block, motion_x, motion_y); break; case CODEC_ID_MPEG4: if (CONFIG_MPEG4_ENCODER) ff_mpeg4_encode_mb(s, s->block, motion_x, motion_y); break; case CODEC_ID_MSMPEG4V2: case CODEC_ID_MSMPEG4V3: case CODEC_ID_WMV1: if (CONFIG_MSMPEG4_ENCODER) ff_msmpeg4_encode_mb(s, s->block, motion_x, motion_y); break; case CODEC_ID_WMV2: if (CONFIG_WMV2_ENCODER) ff_wmv2_encode_mb(s, s->block, motion_x, motion_y); break; case CODEC_ID_H261: if (CONFIG_H261_ENCODER) ff_h261_encode_mb(s, s->block, motion_x, motion_y); break; case CODEC_ID_H263: case CODEC_ID_H263P: case CODEC_ID_FLV1: case CODEC_ID_RV10: case CODEC_ID_RV20: if (CONFIG_H263_ENCODER) ff_h263_encode_mb(s, s->block, motion_x, motion_y); break; case CODEC_ID_MJPEG: if (CONFIG_MJPEG_ENCODER) ff_mjpeg_encode_mb(s, s->block); break; default: assert(0); } }
['static av_always_inline void encode_mb_internal(MpegEncContext *s,\n int motion_x, int motion_y,\n int mb_block_height,\n int mb_block_count)\n{\n int16_t weight[8][64];\n DCTELEM orig[8][64];\n const int mb_x = s->mb_x;\n const int mb_y = s->mb_y;\n int i;\n int skip_dct[8];\n int dct_offset = s->linesize * 8;\n uint8_t *ptr_y, *ptr_cb, *ptr_cr;\n int wrap_y, wrap_c;\n for (i = 0; i < mb_block_count; i++)\n skip_dct[i] = s->skipdct;\n if (s->adaptive_quant) {\n const int last_qp = s->qscale;\n const int mb_xy = mb_x + mb_y * s->mb_stride;\n s->lambda = s->lambda_table[mb_xy];\n update_qscale(s);\n if (!(s->mpv_flags & FF_MPV_FLAG_QP_RD)) {\n s->qscale = s->current_picture_ptr->f.qscale_table[mb_xy];\n s->dquant = s->qscale - last_qp;\n if (s->out_format == FMT_H263) {\n s->dquant = av_clip(s->dquant, -2, 2);\n if (s->codec_id == CODEC_ID_MPEG4) {\n if (!s->mb_intra) {\n if (s->pict_type == AV_PICTURE_TYPE_B) {\n if (s->dquant & 1 || s->mv_dir & MV_DIRECT)\n s->dquant = 0;\n }\n if (s->mv_type == MV_TYPE_8X8)\n s->dquant = 0;\n }\n }\n }\n }\n ff_set_qscale(s, last_qp + s->dquant);\n } else if (s->mpv_flags & FF_MPV_FLAG_QP_RD)\n ff_set_qscale(s, s->qscale + s->dquant);\n wrap_y = s->linesize;\n wrap_c = s->uvlinesize;\n ptr_y = s->new_picture.f.data[0] +\n (mb_y * 16 * wrap_y) + mb_x * 16;\n ptr_cb = s->new_picture.f.data[1] +\n (mb_y * mb_block_height * wrap_c) + mb_x * 8;\n ptr_cr = s->new_picture.f.data[2] +\n (mb_y * mb_block_height * wrap_c) + mb_x * 8;\n if (mb_x * 16 + 16 > s->width || mb_y * 16 + 16 > s->height) {\n uint8_t *ebuf = s->edge_emu_buffer + 32;\n s->dsp.emulated_edge_mc(ebuf, ptr_y, wrap_y, 16, 16, mb_x * 16,\n mb_y * 16, s->width, s->height);\n ptr_y = ebuf;\n s->dsp.emulated_edge_mc(ebuf + 18 * wrap_y, ptr_cb, wrap_c, 8,\n mb_block_height, mb_x * 8, mb_y * 8,\n s->width >> 1, s->height >> 1);\n ptr_cb = ebuf + 18 * wrap_y;\n s->dsp.emulated_edge_mc(ebuf + 18 * wrap_y + 8, ptr_cr, wrap_c, 8,\n mb_block_height, mb_x * 8, mb_y * 8,\n s->width >> 1, s->height >> 1);\n ptr_cr = ebuf + 18 * wrap_y + 8;\n }\n if (s->mb_intra) {\n if (s->flags & CODEC_FLAG_INTERLACED_DCT) {\n int progressive_score, interlaced_score;\n s->interlaced_dct = 0;\n progressive_score = s->dsp.ildct_cmp[4](s, ptr_y,\n NULL, wrap_y, 8) +\n s->dsp.ildct_cmp[4](s, ptr_y + wrap_y * 8,\n NULL, wrap_y, 8) - 400;\n if (progressive_score > 0) {\n interlaced_score = s->dsp.ildct_cmp[4](s, ptr_y,\n NULL, wrap_y * 2, 8) +\n s->dsp.ildct_cmp[4](s, ptr_y + wrap_y,\n NULL, wrap_y * 2, 8);\n if (progressive_score > interlaced_score) {\n s->interlaced_dct = 1;\n dct_offset = wrap_y;\n wrap_y <<= 1;\n if (s->chroma_format == CHROMA_422)\n wrap_c <<= 1;\n }\n }\n }\n s->dsp.get_pixels(s->block[0], ptr_y , wrap_y);\n s->dsp.get_pixels(s->block[1], ptr_y + 8 , wrap_y);\n s->dsp.get_pixels(s->block[2], ptr_y + dct_offset , wrap_y);\n s->dsp.get_pixels(s->block[3], ptr_y + dct_offset + 8 , wrap_y);\n if (s->flags & CODEC_FLAG_GRAY) {\n skip_dct[4] = 1;\n skip_dct[5] = 1;\n } else {\n s->dsp.get_pixels(s->block[4], ptr_cb, wrap_c);\n s->dsp.get_pixels(s->block[5], ptr_cr, wrap_c);\n if (!s->chroma_y_shift) {\n s->dsp.get_pixels(s->block[6],\n ptr_cb + (dct_offset >> 1), wrap_c);\n s->dsp.get_pixels(s->block[7],\n ptr_cr + (dct_offset >> 1), wrap_c);\n }\n }\n } else {\n op_pixels_func (*op_pix)[4];\n qpel_mc_func (*op_qpix)[16];\n uint8_t *dest_y, *dest_cb, *dest_cr;\n dest_y = s->dest[0];\n dest_cb = s->dest[1];\n dest_cr = s->dest[2];\n if ((!s->no_rounding) || s->pict_type == AV_PICTURE_TYPE_B) {\n op_pix = s->dsp.put_pixels_tab;\n op_qpix = s->dsp.put_qpel_pixels_tab;\n } else {\n op_pix = s->dsp.put_no_rnd_pixels_tab;\n op_qpix = s->dsp.put_no_rnd_qpel_pixels_tab;\n }\n if (s->mv_dir & MV_DIR_FORWARD) {\n MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f.data,\n op_pix, op_qpix);\n op_pix = s->dsp.avg_pixels_tab;\n op_qpix = s->dsp.avg_qpel_pixels_tab;\n }\n if (s->mv_dir & MV_DIR_BACKWARD) {\n MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f.data,\n op_pix, op_qpix);\n }\n if (s->flags & CODEC_FLAG_INTERLACED_DCT) {\n int progressive_score, interlaced_score;\n s->interlaced_dct = 0;\n progressive_score = s->dsp.ildct_cmp[0](s, dest_y,\n ptr_y, wrap_y,\n 8) +\n s->dsp.ildct_cmp[0](s, dest_y + wrap_y * 8,\n ptr_y + wrap_y * 8, wrap_y,\n 8) - 400;\n if (s->avctx->ildct_cmp == FF_CMP_VSSE)\n progressive_score -= 400;\n if (progressive_score > 0) {\n interlaced_score = s->dsp.ildct_cmp[0](s, dest_y,\n ptr_y,\n wrap_y * 2, 8) +\n s->dsp.ildct_cmp[0](s, dest_y + wrap_y,\n ptr_y + wrap_y,\n wrap_y * 2, 8);\n if (progressive_score > interlaced_score) {\n s->interlaced_dct = 1;\n dct_offset = wrap_y;\n wrap_y <<= 1;\n if (s->chroma_format == CHROMA_422)\n wrap_c <<= 1;\n }\n }\n }\n s->dsp.diff_pixels(s->block[0], ptr_y, dest_y, wrap_y);\n s->dsp.diff_pixels(s->block[1], ptr_y + 8, dest_y + 8, wrap_y);\n s->dsp.diff_pixels(s->block[2], ptr_y + dct_offset,\n dest_y + dct_offset, wrap_y);\n s->dsp.diff_pixels(s->block[3], ptr_y + dct_offset + 8,\n dest_y + dct_offset + 8, wrap_y);\n if (s->flags & CODEC_FLAG_GRAY) {\n skip_dct[4] = 1;\n skip_dct[5] = 1;\n } else {\n s->dsp.diff_pixels(s->block[4], ptr_cb, dest_cb, wrap_c);\n s->dsp.diff_pixels(s->block[5], ptr_cr, dest_cr, wrap_c);\n if (!s->chroma_y_shift) {\n s->dsp.diff_pixels(s->block[6], ptr_cb + (dct_offset >> 1),\n dest_cb + (dct_offset >> 1), wrap_c);\n s->dsp.diff_pixels(s->block[7], ptr_cr + (dct_offset >> 1),\n dest_cr + (dct_offset >> 1), wrap_c);\n }\n }\n if (s->current_picture.mc_mb_var[s->mb_stride * mb_y + mb_x] <\n 2 * s->qscale * s->qscale) {\n if (s->dsp.sad[1](NULL, ptr_y , dest_y,\n wrap_y, 8) < 20 * s->qscale)\n skip_dct[0] = 1;\n if (s->dsp.sad[1](NULL, ptr_y + 8,\n dest_y + 8, wrap_y, 8) < 20 * s->qscale)\n skip_dct[1] = 1;\n if (s->dsp.sad[1](NULL, ptr_y + dct_offset,\n dest_y + dct_offset, wrap_y, 8) < 20 * s->qscale)\n skip_dct[2] = 1;\n if (s->dsp.sad[1](NULL, ptr_y + dct_offset + 8,\n dest_y + dct_offset + 8,\n wrap_y, 8) < 20 * s->qscale)\n skip_dct[3] = 1;\n if (s->dsp.sad[1](NULL, ptr_cb, dest_cb,\n wrap_c, 8) < 20 * s->qscale)\n skip_dct[4] = 1;\n if (s->dsp.sad[1](NULL, ptr_cr, dest_cr,\n wrap_c, 8) < 20 * s->qscale)\n skip_dct[5] = 1;\n if (!s->chroma_y_shift) {\n if (s->dsp.sad[1](NULL, ptr_cb + (dct_offset >> 1),\n dest_cb + (dct_offset >> 1),\n wrap_c, 8) < 20 * s->qscale)\n skip_dct[6] = 1;\n if (s->dsp.sad[1](NULL, ptr_cr + (dct_offset >> 1),\n dest_cr + (dct_offset >> 1),\n wrap_c, 8) < 20 * s->qscale)\n skip_dct[7] = 1;\n }\n }\n }\n if (s->quantizer_noise_shaping) {\n if (!skip_dct[0])\n get_visual_weight(weight[0], ptr_y , wrap_y);\n if (!skip_dct[1])\n get_visual_weight(weight[1], ptr_y + 8, wrap_y);\n if (!skip_dct[2])\n get_visual_weight(weight[2], ptr_y + dct_offset , wrap_y);\n if (!skip_dct[3])\n get_visual_weight(weight[3], ptr_y + dct_offset + 8, wrap_y);\n if (!skip_dct[4])\n get_visual_weight(weight[4], ptr_cb , wrap_c);\n if (!skip_dct[5])\n get_visual_weight(weight[5], ptr_cr , wrap_c);\n if (!s->chroma_y_shift) {\n if (!skip_dct[6])\n get_visual_weight(weight[6], ptr_cb + (dct_offset >> 1),\n wrap_c);\n if (!skip_dct[7])\n get_visual_weight(weight[7], ptr_cr + (dct_offset >> 1),\n wrap_c);\n }\n memcpy(orig[0], s->block[0], sizeof(DCTELEM) * 64 * mb_block_count);\n }\n assert(s->out_format != FMT_MJPEG || s->qscale == 8);\n {\n for (i = 0; i < mb_block_count; i++) {\n if (!skip_dct[i]) {\n int overflow;\n s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, s->qscale, &overflow);\n if (overflow)\n clip_coeffs(s, s->block[i], s->block_last_index[i]);\n } else\n s->block_last_index[i] = -1;\n }\n if (s->quantizer_noise_shaping) {\n for (i = 0; i < mb_block_count; i++) {\n if (!skip_dct[i]) {\n s->block_last_index[i] =\n dct_quantize_refine(s, s->block[i], weight[i],\n orig[i], i, s->qscale);\n }\n }\n }\n if (s->luma_elim_threshold && !s->mb_intra)\n for (i = 0; i < 4; i++)\n dct_single_coeff_elimination(s, i, s->luma_elim_threshold);\n if (s->chroma_elim_threshold && !s->mb_intra)\n for (i = 4; i < mb_block_count; i++)\n dct_single_coeff_elimination(s, i, s->chroma_elim_threshold);\n if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) {\n for (i = 0; i < mb_block_count; i++) {\n if (s->block_last_index[i] == -1)\n s->coded_score[i] = INT_MAX / 256;\n }\n }\n }\n if ((s->flags & CODEC_FLAG_GRAY) && s->mb_intra) {\n s->block_last_index[4] =\n s->block_last_index[5] = 0;\n s->block[4][0] =\n s->block[5][0] = (1024 + s->c_dc_scale / 2) / s->c_dc_scale;\n }\n if (s->alternate_scan && s->dct_quantize != ff_dct_quantize_c) {\n for (i = 0; i < mb_block_count; i++) {\n int j;\n if (s->block_last_index[i] > 0) {\n for (j = 63; j > 0; j--) {\n if (s->block[i][s->intra_scantable.permutated[j]])\n break;\n }\n s->block_last_index[i] = j;\n }\n }\n }\n switch(s->codec_id){\n case CODEC_ID_MPEG1VIDEO:\n case CODEC_ID_MPEG2VIDEO:\n if (CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER)\n ff_mpeg1_encode_mb(s, s->block, motion_x, motion_y);\n break;\n case CODEC_ID_MPEG4:\n if (CONFIG_MPEG4_ENCODER)\n ff_mpeg4_encode_mb(s, s->block, motion_x, motion_y);\n break;\n case CODEC_ID_MSMPEG4V2:\n case CODEC_ID_MSMPEG4V3:\n case CODEC_ID_WMV1:\n if (CONFIG_MSMPEG4_ENCODER)\n ff_msmpeg4_encode_mb(s, s->block, motion_x, motion_y);\n break;\n case CODEC_ID_WMV2:\n if (CONFIG_WMV2_ENCODER)\n ff_wmv2_encode_mb(s, s->block, motion_x, motion_y);\n break;\n case CODEC_ID_H261:\n if (CONFIG_H261_ENCODER)\n ff_h261_encode_mb(s, s->block, motion_x, motion_y);\n break;\n case CODEC_ID_H263:\n case CODEC_ID_H263P:\n case CODEC_ID_FLV1:\n case CODEC_ID_RV10:\n case CODEC_ID_RV20:\n if (CONFIG_H263_ENCODER)\n ff_h263_encode_mb(s, s->block, motion_x, motion_y);\n break;\n case CODEC_ID_MJPEG:\n if (CONFIG_MJPEG_ENCODER)\n ff_mjpeg_encode_mb(s, s->block);\n break;\n default:\n assert(0);\n }\n}']
34,834
0
https://github.com/libav/libav/blob/3fec44c640ea0c8fd1944e9a41da50a3d7251274/libavcodec/vp3.c/#L1781
static int vp3_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; Vp3DecodeContext *s = avctx->priv_data; GetBitContext gb; static int counter = 0; int i; init_get_bits(&gb, buf, buf_size * 8); if (s->theora && get_bits1(&gb)) { av_log(avctx, AV_LOG_ERROR, "Header packet passed to frame decoder, skipping\n"); return -1; } s->keyframe = !get_bits1(&gb); if (!s->theora) skip_bits(&gb, 1); for (i = 0; i < 3; i++) s->last_qps[i] = s->qps[i]; s->nqps=0; do{ s->qps[s->nqps++]= get_bits(&gb, 6); } while(s->theora >= 0x030200 && s->nqps<3 && get_bits1(&gb)); for (i = s->nqps; i < 3; i++) s->qps[i] = -1; if (s->avctx->debug & FF_DEBUG_PICT_INFO) av_log(s->avctx, AV_LOG_INFO, " VP3 %sframe #%d: Q index = %d\n", s->keyframe?"key":"", counter, s->qps[0]); counter++; if (s->qps[0] != s->last_qps[0]) init_loop_filter(s); for (i = 0; i < s->nqps; i++) if (s->qps[i] != s->last_qps[i] || s->qps[0] != s->last_qps[0]) init_dequantizer(s, i); if (avctx->skip_frame >= AVDISCARD_NONKEY && !s->keyframe) return buf_size; if (s->keyframe) { if (!s->theora) { skip_bits(&gb, 4); skip_bits(&gb, 4); if (s->version) { s->version = get_bits(&gb, 5); if (counter == 1) av_log(s->avctx, AV_LOG_DEBUG, "VP version: %d\n", s->version); } } if (s->version || s->theora) { if (get_bits1(&gb)) av_log(s->avctx, AV_LOG_ERROR, "Warning, unsupported keyframe coding type?!\n"); skip_bits(&gb, 2); } if (s->last_frame.data[0] == s->golden_frame.data[0]) { if (s->golden_frame.data[0]) avctx->release_buffer(avctx, &s->golden_frame); s->last_frame= s->golden_frame; } else { if (s->golden_frame.data[0]) avctx->release_buffer(avctx, &s->golden_frame); if (s->last_frame.data[0]) avctx->release_buffer(avctx, &s->last_frame); } s->golden_frame.reference = 3; if(avctx->get_buffer(avctx, &s->golden_frame) < 0) { av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\n"); return -1; } s->current_frame= s->golden_frame; } else { s->current_frame.reference = 3; if (!s->golden_frame.data[0]) { av_log(s->avctx, AV_LOG_ERROR, "vp3: first frame not a keyframe\n"); return -1; } if(avctx->get_buffer(avctx, &s->current_frame) < 0) { av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\n"); return -1; } } s->current_frame.qscale_table= s->qscale_table; s->current_frame.qstride= 0; init_frame(s, &gb); if (unpack_superblocks(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_superblocks\n"); return -1; } if (unpack_modes(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_modes\n"); return -1; } if (unpack_vectors(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_vectors\n"); return -1; } if (unpack_block_qpis(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_block_qpis\n"); return -1; } if (unpack_dct_coeffs(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_dct_coeffs\n"); return -1; } for (i = 0; i < 3; i++) { if (s->flipped_image) s->data_offset[i] = 0; else s->data_offset[i] = ((s->height>>!!i)-1) * s->current_frame.linesize[i]; } s->last_slice_end = 0; for (i = 0; i < s->c_superblock_height; i++) render_slice(s, i); for (i = 0; i < 3; i++) { int row = (s->height >> (3+!!i)) - 1; apply_loop_filter(s, i, row, row+1); } vp3_draw_horiz_band(s, s->height); *data_size=sizeof(AVFrame); *(AVFrame*)data= s->current_frame; if ((s->last_frame.data[0]) && (s->last_frame.data[0] != s->golden_frame.data[0])) avctx->release_buffer(avctx, &s->last_frame); s->last_frame= s->current_frame; s->current_frame.data[0]= NULL; return buf_size; }
['static int vp3_decode_frame(AVCodecContext *avctx,\n void *data, int *data_size,\n AVPacket *avpkt)\n{\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n Vp3DecodeContext *s = avctx->priv_data;\n GetBitContext gb;\n static int counter = 0;\n int i;\n init_get_bits(&gb, buf, buf_size * 8);\n if (s->theora && get_bits1(&gb))\n {\n av_log(avctx, AV_LOG_ERROR, "Header packet passed to frame decoder, skipping\\n");\n return -1;\n }\n s->keyframe = !get_bits1(&gb);\n if (!s->theora)\n skip_bits(&gb, 1);\n for (i = 0; i < 3; i++)\n s->last_qps[i] = s->qps[i];\n s->nqps=0;\n do{\n s->qps[s->nqps++]= get_bits(&gb, 6);\n } while(s->theora >= 0x030200 && s->nqps<3 && get_bits1(&gb));\n for (i = s->nqps; i < 3; i++)\n s->qps[i] = -1;\n if (s->avctx->debug & FF_DEBUG_PICT_INFO)\n av_log(s->avctx, AV_LOG_INFO, " VP3 %sframe #%d: Q index = %d\\n",\n s->keyframe?"key":"", counter, s->qps[0]);\n counter++;\n if (s->qps[0] != s->last_qps[0])\n init_loop_filter(s);\n for (i = 0; i < s->nqps; i++)\n if (s->qps[i] != s->last_qps[i] || s->qps[0] != s->last_qps[0])\n init_dequantizer(s, i);\n if (avctx->skip_frame >= AVDISCARD_NONKEY && !s->keyframe)\n return buf_size;\n if (s->keyframe) {\n if (!s->theora)\n {\n skip_bits(&gb, 4);\n skip_bits(&gb, 4);\n if (s->version)\n {\n s->version = get_bits(&gb, 5);\n if (counter == 1)\n av_log(s->avctx, AV_LOG_DEBUG, "VP version: %d\\n", s->version);\n }\n }\n if (s->version || s->theora)\n {\n if (get_bits1(&gb))\n av_log(s->avctx, AV_LOG_ERROR, "Warning, unsupported keyframe coding type?!\\n");\n skip_bits(&gb, 2);\n }\n if (s->last_frame.data[0] == s->golden_frame.data[0]) {\n if (s->golden_frame.data[0])\n avctx->release_buffer(avctx, &s->golden_frame);\n s->last_frame= s->golden_frame;\n } else {\n if (s->golden_frame.data[0])\n avctx->release_buffer(avctx, &s->golden_frame);\n if (s->last_frame.data[0])\n avctx->release_buffer(avctx, &s->last_frame);\n }\n s->golden_frame.reference = 3;\n if(avctx->get_buffer(avctx, &s->golden_frame) < 0) {\n av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\\n");\n return -1;\n }\n s->current_frame= s->golden_frame;\n } else {\n s->current_frame.reference = 3;\n if (!s->golden_frame.data[0]) {\n av_log(s->avctx, AV_LOG_ERROR, "vp3: first frame not a keyframe\\n");\n return -1;\n }\n if(avctx->get_buffer(avctx, &s->current_frame) < 0) {\n av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\\n");\n return -1;\n }\n }\n s->current_frame.qscale_table= s->qscale_table;\n s->current_frame.qstride= 0;\n init_frame(s, &gb);\n if (unpack_superblocks(s, &gb)){\n av_log(s->avctx, AV_LOG_ERROR, "error in unpack_superblocks\\n");\n return -1;\n }\n if (unpack_modes(s, &gb)){\n av_log(s->avctx, AV_LOG_ERROR, "error in unpack_modes\\n");\n return -1;\n }\n if (unpack_vectors(s, &gb)){\n av_log(s->avctx, AV_LOG_ERROR, "error in unpack_vectors\\n");\n return -1;\n }\n if (unpack_block_qpis(s, &gb)){\n av_log(s->avctx, AV_LOG_ERROR, "error in unpack_block_qpis\\n");\n return -1;\n }\n if (unpack_dct_coeffs(s, &gb)){\n av_log(s->avctx, AV_LOG_ERROR, "error in unpack_dct_coeffs\\n");\n return -1;\n }\n for (i = 0; i < 3; i++) {\n if (s->flipped_image)\n s->data_offset[i] = 0;\n else\n s->data_offset[i] = ((s->height>>!!i)-1) * s->current_frame.linesize[i];\n }\n s->last_slice_end = 0;\n for (i = 0; i < s->c_superblock_height; i++)\n render_slice(s, i);\n for (i = 0; i < 3; i++) {\n int row = (s->height >> (3+!!i)) - 1;\n apply_loop_filter(s, i, row, row+1);\n }\n vp3_draw_horiz_band(s, s->height);\n *data_size=sizeof(AVFrame);\n *(AVFrame*)data= s->current_frame;\n if ((s->last_frame.data[0]) &&\n (s->last_frame.data[0] != s->golden_frame.data[0]))\n avctx->release_buffer(avctx, &s->last_frame);\n s->last_frame= s->current_frame;\n s->current_frame.data[0]= NULL;\n return buf_size;\n}', 'static inline void init_get_bits(GetBitContext *s,\n const uint8_t *buffer, int bit_size)\n{\n int buffer_size= (bit_size+7)>>3;\n if(buffer_size < 0 || bit_size < 0) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n }\n s->buffer= buffer;\n s->size_in_bits= bit_size;\n s->buffer_end= buffer + buffer_size;\n#ifdef ALT_BITSTREAM_READER\n s->index=0;\n#elif defined LIBMPEG2_BITSTREAM_READER\n s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));\n s->bit_count = 16 + 8*((intptr_t)buffer&1);\n skip_bits_long(s, 0);\n#elif defined A32_BITSTREAM_READER\n s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3));\n s->bit_count = 32 + 8*((intptr_t)buffer&3);\n skip_bits_long(s, 0);\n#endif\n}', 'static inline unsigned int get_bits1(GetBitContext *s){\n#ifdef ALT_BITSTREAM_READER\n unsigned int index= s->index;\n uint8_t result= s->buffer[ index>>3 ];\n#ifdef ALT_BITSTREAM_READER_LE\n result>>= (index&0x07);\n result&= 1;\n#else\n result<<= (index&0x07);\n result>>= 8 - 1;\n#endif\n index++;\n s->index= index;\n return result;\n#else\n return get_bits(s, 1);\n#endif\n}']
34,835
0
https://github.com/openssl/openssl/blob/c62b26fdc6bb176541ec56498090ff6f2ad4a885/crypto/bn/bn_add.c/#L228
int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) { int max,min; register BN_ULONG t1,t2,*ap,*bp,*rp; int i,carry; #if defined(IRIX_CC_BUG) && !defined(LINT) int dummy; #endif bn_check_top(a); bn_check_top(b); if (a->top < b->top) { BNerr(BN_F_BN_USUB,BN_R_ARG2_LT_ARG3); return(0); } max=a->top; min=b->top; if (bn_wexpand(r,max) == NULL) return(0); ap=a->d; bp=b->d; rp=r->d; #if 1 carry=0; for (i=0; i<min; i++) { t1= *(ap++); t2= *(bp++); if (carry) { carry=(t1 <= t2); t1=(t1-t2-1)&BN_MASK2; } else { carry=(t1 < t2); t1=(t1-t2)&BN_MASK2; } #if defined(IRIX_CC_BUG) && !defined(LINT) dummy=t1; #endif *(rp++)=t1&BN_MASK2; } #else carry=bn_sub_words(rp,ap,bp,min); ap+=min; bp+=min; rp+=min; i=min; #endif if (carry) { while (i < max) { i++; t1= *(ap++); t2=(t1-1)&BN_MASK2; *(rp++)=t2; if (t1 > t2) break; } } #if 0 memcpy(rp,ap,sizeof(*rp)*(max-i)); #else if (rp != ap) { for (;;) { if (i++ >= max) break; rp[0]=ap[0]; if (i++ >= max) break; rp[1]=ap[1]; if (i++ >= max) break; rp[2]=ap[2]; if (i++ >= max) break; rp[3]=ap[3]; rp+=4; ap+=4; } } #endif r->top=max; r->neg=0; bn_fix_top(r); return(1); }
['int ec_GFp_simple_oct2point(const EC_GROUP *group, EC_POINT *point,\n\tconst unsigned char *buf, size_t len, BN_CTX *ctx)\n\t{\n\tpoint_conversion_form_t form;\n\tint y_bit;\n\tBN_CTX *new_ctx = NULL;\n\tBIGNUM *x, *y;\n\tsize_t field_len, enc_len;\n\tint ret = 0;\n\tif (len <= 0)\n\t\t{\n\t\tECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_BUFFER_TOO_SMALL);\n\t\treturn 0;\n\t\t}\n\tform = buf[0];\n\ty_bit = form & 1;\n\tform = form & ~1;\n\tif ((form != 0)\t&& (form != POINT_CONVERSION_COMPRESSED)\n\t\t&& (form != POINT_CONVERSION_UNCOMPRESSED)\n\t\t&& (form != POINT_CONVERSION_HYBRID))\n\t\t{\n\t\tECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n\t\treturn 0;\n\t\t}\n\tif ((form == 0 || form == POINT_CONVERSION_UNCOMPRESSED) && y_bit)\n\t\t{\n\t\tECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n\t\treturn 0;\n\t\t}\n\tif (form == 0)\n\t\t{\n\t\tif (len != 1)\n\t\t\t{\n\t\t\tECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n\t\t\treturn 0;\n\t\t\t}\n\t\treturn EC_POINT_set_to_infinity(group, point);\n\t\t}\n\tfield_len = BN_num_bytes(&group->field);\n\tenc_len = (form == POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2*field_len;\n\tif (len != enc_len)\n\t\t{\n\t\tECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n\t\treturn 0;\n\t\t}\n\tif (ctx == NULL)\n\t\t{\n\t\tctx = new_ctx = BN_CTX_new();\n\t\tif (ctx == NULL)\n\t\t\treturn 0;\n\t\t}\n\tBN_CTX_start(ctx);\n\tx = BN_CTX_get(ctx);\n\ty = BN_CTX_get(ctx);\n\tif (y == NULL) goto err;\n\tif (!BN_bin2bn(buf + 1, field_len, x)) goto err;\n\tif (BN_ucmp(x, &group->field) >= 0)\n\t\t{\n\t\tECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n\t\tgoto err;\n\t\t}\n\tif (form != POINT_CONVERSION_COMPRESSED)\n\t\t{\n\t\tif (!BN_bin2bn(buf + 1 + field_len, field_len, y)) goto err;\n\t\tif (BN_ucmp(y, &group->field) >= 0)\n\t\t\t{\n\t\t\tECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (form == POINT_CONVERSION_HYBRID)\n\t\t\t{\n\t\t\tif (y_bit != BN_is_odd(y))\n\t\t\t\t{\n\t\t\t\tECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif (form == POINT_CONVERSION_COMPRESSED)\n\t\t{\n\t\tBIGNUM *tmp1, *tmp2;\n\t\ttmp1 = BN_CTX_get(ctx);\n\t\ttmp2 = BN_CTX_get(ctx);\n\t\tif (tmp2 == NULL) goto err;\n\t\tif (!BN_mod_sqr(tmp2, x, &group->field, ctx)) goto err;\n\t\tif (!BN_mod_mul(tmp1, tmp2, x, &group->field, ctx)) goto err;\n\t\tif (group->a_is_minus3)\n\t\t\t{\n\t\t\tif (!BN_mod_lshift1_quick(tmp2, x, &group->field)) goto err;\n\t\t\tif (!BN_mod_add_quick(tmp2, tmp2, x, &group->field)) goto err;\n\t\t\tif (!BN_mod_sub_quick(tmp1, tmp1, tmp2, &group->field)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_mod_mul(tmp2, &group->a, x, &group->field, ctx)) goto err;\n\t\t\tif (!BN_mod_add_quick(tmp1, tmp1, tmp2, &group->field)) goto err;\n\t\t\t}\n\t\tif (!BN_mod_add_quick(tmp1, tmp1, &group->b, &group->field)) goto err;\n\t\tif (!BN_mod_sqrt(y, tmp1, &group->field, ctx))\n\t\t\t{\n\t\t\tECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, ERR_R_BN_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (y_bit != BN_is_odd(y))\n\t\t\t{\n\t\t\tif (BN_is_zero(y))\n\t\t\t\t{\n\t\t\t\tECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif (!BN_usub(y, &group->field, y)) goto err;\n\t\t\t}\n\t\tif (y_bit != BN_is_odd(y))\n\t\t\t{\n\t\t\tECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, ERR_R_INTERNAL_ERROR);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tif (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;\n\tif (!EC_POINT_is_on_curve(group, point, ctx))\n\t\t{\n\t\tECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_POINT_IS_NOT_ON_CURVE);\n\t\tgoto err;\n\t\t}\n\tret = 1;\n err:\n\tBN_CTX_end(ctx);\n\tif (new_ctx != NULL)\n\t\tBN_CTX_free(new_ctx);\n\treturn ret;\n\t}', 'BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)\n\t{\n\tBIGNUM *ret = in;\n\tint err = 1;\n\tint r;\n\tBIGNUM *b, *q, *t, *x, *y;\n\tint e, i, j;\n\tif (!BN_is_odd(p) || BN_abs_is_word(p, 1))\n\t\t{\n\t\tif (BN_abs_is_word(p, 2))\n\t\t\t{\n\t\t\tif (ret == NULL)\n\t\t\t\tret = BN_new();\n\t\t\tif (ret == NULL)\n\t\t\t\tgoto end;\n\t\t\tif (!BN_set_word(ret, BN_is_bit_set(a, 0)))\n\t\t\t\t{\n\t\t\t\tBN_free(ret);\n\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\treturn ret;\n\t\t\t}\n\t\tBNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);\n\t\treturn(NULL);\n\t\t}\n\tif (BN_is_zero(a) || BN_is_one(a))\n\t\t{\n\t\tif (ret == NULL)\n\t\t\tret = BN_new();\n\t\tif (ret == NULL)\n\t\t\tgoto end;\n\t\tif (!BN_set_word(ret, BN_is_one(a)))\n\t\t\t{\n\t\t\tBN_free(ret);\n\t\t\treturn NULL;\n\t\t\t}\n\t\treturn ret;\n\t\t}\n#if 0\n\tr = BN_kronecker(a, p, ctx);\n\tif (r < -1) return NULL;\n\tif (r == -1)\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);\n\t\treturn(NULL);\n\t\t}\n#endif\n\tBN_CTX_start(ctx);\n\tb = BN_CTX_get(ctx);\n\tq = BN_CTX_get(ctx);\n\tt = BN_CTX_get(ctx);\n\tx = BN_CTX_get(ctx);\n\ty = BN_CTX_get(ctx);\n\tif (y == NULL) goto end;\n\tif (ret == NULL)\n\t\tret = BN_new();\n\tif (ret == NULL) goto end;\n\te = 1;\n\twhile (!BN_is_bit_set(p, e))\n\t\te++;\n\tif (e == 1)\n\t\t{\n\t\tif (!BN_rshift(q, p, 2)) goto end;\n\t\tq->neg = 0;\n\t\tif (!BN_add_word(q, 1)) goto end;\n\t\tif (!BN_mod_exp(ret, a, q, p, ctx)) goto end;\n\t\terr = 0;\n\t\tgoto end;\n\t\t}\n\tif (e == 2)\n\t\t{\n\t\tif (a->neg || BN_ucmp(a, p) >= 0)\n\t\t\t{\n\t\t\tif (!BN_nnmod(x, a, p, ctx)) goto end;\n\t\t\ta = x;\n\t\t\t}\n\t\tif (!BN_mod_lshift1_quick(t, a, p)) goto end;\n\t\tif (!BN_rshift(q, p, 3)) goto end;\n\t\tq->neg = 0;\n\t\tif (!BN_mod_exp(b, t, q, p, ctx)) goto end;\n\t\tif (!BN_mod_sqr(y, b, p, ctx)) goto end;\n\t\tif (!BN_mod_mul(t, t, y, p, ctx)) goto end;\n\t\tif (!BN_sub_word(t, 1)) goto end;\n\t\tif (!BN_mod_mul(x, a, b, p, ctx)) goto end;\n\t\tif (!BN_mod_mul(x, x, t, p, ctx)) goto end;\n\t\tif (!BN_copy(ret, x)) goto end;\n\t\terr = 0;\n\t\tgoto end;\n\t\t}\n\tif (!BN_copy(q, p)) goto end;\n\tq->neg = 0;\n\ti = 2;\n\tdo\n\t\t{\n\t\tif (i < 22)\n\t\t\t{\n\t\t\tif (!BN_set_word(y, i)) goto end;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_pseudo_rand(y, BN_num_bits(p), 0, 0)) goto end;\n\t\t\tif (BN_ucmp(y, p) >= 0)\n\t\t\t\t{\n\t\t\t\tif (!(p->neg ? BN_add : BN_sub)(y, y, p)) goto end;\n\t\t\t\t}\n\t\t\tif (BN_is_zero(y))\n\t\t\t\tif (!BN_set_word(y, i)) goto end;\n\t\t\t}\n\t\tr = BN_kronecker(y, q, ctx);\n\t\tif (r < -1) goto end;\n\t\tif (r == 0)\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\twhile (r == 1 && ++i < 82);\n\tif (r != -1)\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_SQRT, BN_R_TOO_MANY_ITERATIONS);\n\t\tgoto end;\n\t\t}\n\tif (!BN_rshift(q, q, e)) goto end;\n\tif (!BN_mod_exp(y, y, q, p, ctx)) goto end;\n\tif (BN_is_one(y))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);\n\t\tgoto end;\n\t\t}\n\tif (!BN_rshift1(t, q)) goto end;\n\tif (BN_is_zero(t))\n\t\t{\n\t\tif (!BN_nnmod(t, a, p, ctx)) goto end;\n\t\tif (BN_is_zero(t))\n\t\t\t{\n\t\t\tif (!BN_zero(ret)) goto end;\n\t\t\terr = 0;\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n\t\t\tif (!BN_one(x)) goto end;\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_mod_exp(x, a, t, p, ctx)) goto end;\n\t\tif (BN_is_zero(x))\n\t\t\t{\n\t\t\tif (!BN_zero(ret)) goto end;\n\t\t\terr = 0;\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif (!BN_mod_sqr(b, x, p, ctx)) goto end;\n\tif (!BN_mod_mul(b, b, a, p, ctx)) goto end;\n\tif (!BN_mod_mul(x, x, a, p, ctx)) goto end;\n\twhile (1)\n\t\t{\n\t\tif (BN_is_one(b))\n\t\t\t{\n\t\t\tif (!BN_copy(ret, x)) goto end;\n\t\t\terr = 0;\n\t\t\tgoto end;\n\t\t\t}\n\t\ti = 1;\n\t\tif (!BN_mod_sqr(t, b, p, ctx)) goto end;\n\t\twhile (!BN_is_one(t))\n\t\t\t{\n\t\t\ti++;\n\t\t\tif (i == e)\n\t\t\t\t{\n\t\t\t\tBNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tif (!BN_mod_mul(t, t, t, p, ctx)) goto end;\n\t\t\t}\n\t\tif (!BN_copy(t, y)) goto end;\n\t\tfor (j = e - i - 1; j > 0; j--)\n\t\t\t{\n\t\t\tif (!BN_mod_sqr(t, t, p, ctx)) goto end;\n\t\t\t}\n\t\tif (!BN_mod_mul(y, t, t, p, ctx)) goto end;\n\t\tif (!BN_mod_mul(x, x, t, p, ctx)) goto end;\n\t\tif (!BN_mod_mul(b, b, y, p, ctx)) goto end;\n\t\te = i;\n\t\t}\n end:\n\tif (err)\n\t\t{\n\t\tif (ret != NULL && ret != in)\n\t\t\t{\n\t\t\tBN_clear_free(ret);\n\t\t\t}\n\t\tret = NULL;\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn ret;\n\t}', 'int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n\t{\n\tint max,min;\n\tregister BN_ULONG t1,t2,*ap,*bp,*rp;\n\tint i,carry;\n#if defined(IRIX_CC_BUG) && !defined(LINT)\n\tint dummy;\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tif (a->top < b->top)\n\t\t{\n\t\tBNerr(BN_F_BN_USUB,BN_R_ARG2_LT_ARG3);\n\t\treturn(0);\n\t\t}\n\tmax=a->top;\n\tmin=b->top;\n\tif (bn_wexpand(r,max) == NULL) return(0);\n\tap=a->d;\n\tbp=b->d;\n\trp=r->d;\n#if 1\n\tcarry=0;\n\tfor (i=0; i<min; i++)\n\t\t{\n\t\tt1= *(ap++);\n\t\tt2= *(bp++);\n\t\tif (carry)\n\t\t\t{\n\t\t\tcarry=(t1 <= t2);\n\t\t\tt1=(t1-t2-1)&BN_MASK2;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tcarry=(t1 < t2);\n\t\t\tt1=(t1-t2)&BN_MASK2;\n\t\t\t}\n#if defined(IRIX_CC_BUG) && !defined(LINT)\n\t\tdummy=t1;\n#endif\n\t\t*(rp++)=t1&BN_MASK2;\n\t\t}\n#else\n\tcarry=bn_sub_words(rp,ap,bp,min);\n\tap+=min;\n\tbp+=min;\n\trp+=min;\n\ti=min;\n#endif\n\tif (carry)\n\t\t{\n\t\twhile (i < max)\n\t\t\t{\n\t\t\ti++;\n\t\t\tt1= *(ap++);\n\t\t\tt2=(t1-1)&BN_MASK2;\n\t\t\t*(rp++)=t2;\n\t\t\tif (t1 > t2) break;\n\t\t\t}\n\t\t}\n#if 0\n\tmemcpy(rp,ap,sizeof(*rp)*(max-i));\n#else\n\tif (rp != ap)\n\t\t{\n\t\tfor (;;)\n\t\t\t{\n\t\t\tif (i++ >= max) break;\n\t\t\trp[0]=ap[0];\n\t\t\tif (i++ >= max) break;\n\t\t\trp[1]=ap[1];\n\t\t\tif (i++ >= max) break;\n\t\t\trp[2]=ap[2];\n\t\t\tif (i++ >= max) break;\n\t\t\trp[3]=ap[3];\n\t\t\trp+=4;\n\t\t\tap+=4;\n\t\t\t}\n\t\t}\n#endif\n\tr->top=max;\n\tr->neg=0;\n\tbn_fix_top(r);\n\treturn(1);\n\t}']
34,836
0
https://github.com/nginx/nginx/blob/1596399e8232e1398e5b46b7654407c9059cfcbd/src/http/ngx_http_script.c/#L121
ngx_int_t ngx_http_compile_complex_value(ngx_http_compile_complex_value_t *ccv) { ngx_str_t *v; ngx_uint_t i, n, nv, nc; ngx_array_t flushes, lengths, values, *pf, *pl, *pv; ngx_http_script_compile_t sc; v = ccv->value; nv = 0; nc = 0; for (i = 0; i < v->len; i++) { if (v->data[i] == '$') { if (v->data[i + 1] >= '1' && v->data[i + 1] <= '9') { nc++; } else { nv++; } } } if ((v->len == 0 || v->data[0] != '$') && (ccv->conf_prefix || ccv->root_prefix)) { if (ngx_conf_full_name(ccv->cf->cycle, v, ccv->conf_prefix) != NGX_OK) { return NGX_ERROR; } ccv->conf_prefix = 0; ccv->root_prefix = 0; } ccv->complex_value->value = *v; ccv->complex_value->flushes = NULL; ccv->complex_value->lengths = NULL; ccv->complex_value->values = NULL; if (nv == 0 && nc == 0) { return NGX_OK; } n = nv + 1; if (ngx_array_init(&flushes, ccv->cf->pool, n, sizeof(ngx_uint_t)) != NGX_OK) { return NGX_ERROR; } n = nv * (2 * sizeof(ngx_http_script_copy_code_t) + sizeof(ngx_http_script_var_code_t)) + sizeof(uintptr_t); if (ngx_array_init(&lengths, ccv->cf->pool, n, 1) != NGX_OK) { return NGX_ERROR; } n = (nv * (2 * sizeof(ngx_http_script_copy_code_t) + sizeof(ngx_http_script_var_code_t)) + sizeof(uintptr_t) + v->len + sizeof(uintptr_t) - 1) & ~(sizeof(uintptr_t) - 1); if (ngx_array_init(&values, ccv->cf->pool, n, 1) != NGX_OK) { return NGX_ERROR; } pf = &flushes; pl = &lengths; pv = &values; ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); sc.cf = ccv->cf; sc.source = v; sc.flushes = &pf; sc.lengths = &pl; sc.values = &pv; sc.complete_lengths = 1; sc.complete_values = 1; sc.zero = ccv->zero; sc.conf_prefix = ccv->conf_prefix; sc.root_prefix = ccv->root_prefix; if (ngx_http_script_compile(&sc) != NGX_OK) { return NGX_ERROR; } if (flushes.nelts) { ccv->complex_value->flushes = flushes.elts; ccv->complex_value->flushes[flushes.nelts] = (ngx_uint_t) -1; } ccv->complex_value->lengths = lengths.elts; ccv->complex_value->values = values.elts; return NGX_OK; }
['static char *\nngx_http_disable_symlinks(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)\n{\n ngx_http_core_loc_conf_t *clcf = conf;\n ngx_str_t *value;\n ngx_uint_t i;\n ngx_http_compile_complex_value_t ccv;\n if (clcf->disable_symlinks != NGX_CONF_UNSET_UINT) {\n return "is duplicate";\n }\n value = cf->args->elts;\n for (i = 1; i < cf->args->nelts; i++) {\n if (ngx_strcmp(value[i].data, "off") == 0) {\n clcf->disable_symlinks = NGX_DISABLE_SYMLINKS_OFF;\n continue;\n }\n if (ngx_strcmp(value[i].data, "if_not_owner") == 0) {\n clcf->disable_symlinks = NGX_DISABLE_SYMLINKS_NOTOWNER;\n continue;\n }\n if (ngx_strcmp(value[i].data, "on") == 0) {\n clcf->disable_symlinks = NGX_DISABLE_SYMLINKS_ON;\n continue;\n }\n if (ngx_strncmp(value[i].data, "from=", 5) == 0) {\n value[i].len -= 5;\n value[i].data += 5;\n ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));\n ccv.cf = cf;\n ccv.value = &value[i];\n ccv.complex_value = ngx_palloc(cf->pool,\n sizeof(ngx_http_complex_value_t));\n if (ccv.complex_value == NULL) {\n return NGX_CONF_ERROR;\n }\n if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {\n return NGX_CONF_ERROR;\n }\n clcf->disable_symlinks_from = ccv.complex_value;\n continue;\n }\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "invalid parameter \\"%V\\"", &value[i]);\n return NGX_CONF_ERROR;\n }\n if (clcf->disable_symlinks == NGX_CONF_UNSET_UINT) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "\\"%V\\" must have \\"off\\", \\"on\\" "\n "or \\"if_not_owner\\" parameter",\n &cmd->name);\n return NGX_CONF_ERROR;\n }\n if (cf->args->nelts == 2) {\n clcf->disable_symlinks_from = NULL;\n return NGX_CONF_OK;\n }\n if (clcf->disable_symlinks_from == NGX_CONF_UNSET_PTR) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "duplicate parameters \\"%V %V\\"",\n &value[1], &value[2]);\n return NGX_CONF_ERROR;\n }\n if (clcf->disable_symlinks == NGX_DISABLE_SYMLINKS_OFF) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "\\"from=\\" cannot be used with \\"off\\" parameter");\n return NGX_CONF_ERROR;\n }\n return NGX_CONF_OK;\n}', "ngx_int_t\nngx_http_compile_complex_value(ngx_http_compile_complex_value_t *ccv)\n{\n ngx_str_t *v;\n ngx_uint_t i, n, nv, nc;\n ngx_array_t flushes, lengths, values, *pf, *pl, *pv;\n ngx_http_script_compile_t sc;\n v = ccv->value;\n nv = 0;\n nc = 0;\n for (i = 0; i < v->len; i++) {\n if (v->data[i] == '$') {\n if (v->data[i + 1] >= '1' && v->data[i + 1] <= '9') {\n nc++;\n } else {\n nv++;\n }\n }\n }\n if ((v->len == 0 || v->data[0] != '$')\n && (ccv->conf_prefix || ccv->root_prefix))\n {\n if (ngx_conf_full_name(ccv->cf->cycle, v, ccv->conf_prefix) != NGX_OK) {\n return NGX_ERROR;\n }\n ccv->conf_prefix = 0;\n ccv->root_prefix = 0;\n }\n ccv->complex_value->value = *v;\n ccv->complex_value->flushes = NULL;\n ccv->complex_value->lengths = NULL;\n ccv->complex_value->values = NULL;\n if (nv == 0 && nc == 0) {\n return NGX_OK;\n }\n n = nv + 1;\n if (ngx_array_init(&flushes, ccv->cf->pool, n, sizeof(ngx_uint_t))\n != NGX_OK)\n {\n return NGX_ERROR;\n }\n n = nv * (2 * sizeof(ngx_http_script_copy_code_t)\n + sizeof(ngx_http_script_var_code_t))\n + sizeof(uintptr_t);\n if (ngx_array_init(&lengths, ccv->cf->pool, n, 1) != NGX_OK) {\n return NGX_ERROR;\n }\n n = (nv * (2 * sizeof(ngx_http_script_copy_code_t)\n + sizeof(ngx_http_script_var_code_t))\n + sizeof(uintptr_t)\n + v->len\n + sizeof(uintptr_t) - 1)\n & ~(sizeof(uintptr_t) - 1);\n if (ngx_array_init(&values, ccv->cf->pool, n, 1) != NGX_OK) {\n return NGX_ERROR;\n }\n pf = &flushes;\n pl = &lengths;\n pv = &values;\n ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));\n sc.cf = ccv->cf;\n sc.source = v;\n sc.flushes = &pf;\n sc.lengths = &pl;\n sc.values = &pv;\n sc.complete_lengths = 1;\n sc.complete_values = 1;\n sc.zero = ccv->zero;\n sc.conf_prefix = ccv->conf_prefix;\n sc.root_prefix = ccv->root_prefix;\n if (ngx_http_script_compile(&sc) != NGX_OK) {\n return NGX_ERROR;\n }\n if (flushes.nelts) {\n ccv->complex_value->flushes = flushes.elts;\n ccv->complex_value->flushes[flushes.nelts] = (ngx_uint_t) -1;\n }\n ccv->complex_value->lengths = lengths.elts;\n ccv->complex_value->values = values.elts;\n return NGX_OK;\n}"]
34,837
0
https://github.com/libav/libav/blob/10d39405fa82473367e1ba1ed3c4ecbeca2a7986/ffmpeg.c/#L3689
static void opt_output_file(const char *filename) { AVFormatContext *oc; int err, use_video, use_audio, use_subtitle; int input_has_video, input_has_audio, input_has_subtitle; AVFormatParameters params, *ap = &params; AVOutputFormat *file_oformat; if (!strcmp(filename, "-")) filename = "pipe:"; oc = avformat_alloc_context(); if (!oc) { print_error(filename, AVERROR(ENOMEM)); ffmpeg_exit(1); } if (last_asked_format) { file_oformat = av_guess_format(last_asked_format, NULL, NULL); if (!file_oformat) { fprintf(stderr, "Requested output format '%s' is not a suitable output format\n", last_asked_format); ffmpeg_exit(1); } last_asked_format = NULL; } else { file_oformat = av_guess_format(NULL, filename, NULL); if (!file_oformat) { fprintf(stderr, "Unable to find a suitable output format for '%s'\n", filename); ffmpeg_exit(1); } } oc->oformat = file_oformat; av_strlcpy(oc->filename, filename, sizeof(oc->filename)); if (!strcmp(file_oformat->name, "ffm") && av_strstart(filename, "http:", NULL)) { int err = read_ffserver_streams(oc, filename); if (err < 0) { print_error(filename, err); ffmpeg_exit(1); } } else { use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name; use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name; use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name; if (nb_input_files > 0) { check_audio_video_sub_inputs(&input_has_video, &input_has_audio, &input_has_subtitle); if (!input_has_video) use_video = 0; if (!input_has_audio) use_audio = 0; if (!input_has_subtitle) use_subtitle = 0; } if (audio_disable) use_audio = 0; if (video_disable) use_video = 0; if (subtitle_disable) use_subtitle = 0; if (use_video) new_video_stream(oc, nb_output_files); if (use_audio) new_audio_stream(oc, nb_output_files); if (use_subtitle) new_subtitle_stream(oc, nb_output_files); oc->timestamp = recording_timestamp; av_metadata_copy(&oc->metadata, metadata, 0); av_metadata_free(&metadata); } output_files[nb_output_files++] = oc; if (oc->oformat->flags & AVFMT_NEEDNUMBER) { if (!av_filename_number_test(oc->filename)) { print_error(oc->filename, AVERROR(EINVAL)); ffmpeg_exit(1); } } if (!(oc->oformat->flags & AVFMT_NOFILE)) { if (!file_overwrite && (strchr(filename, ':') == NULL || filename[1] == ':' || av_strstart(filename, "file:", NULL))) { if (avio_check(filename, 0) == 0) { if (!using_stdin) { fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename); fflush(stderr); if (!read_yesno()) { fprintf(stderr, "Not overwriting - exiting\n"); ffmpeg_exit(1); } } else { fprintf(stderr,"File '%s' already exists. Exiting.\n", filename); ffmpeg_exit(1); } } } if ((err = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE)) < 0) { print_error(filename, err); ffmpeg_exit(1); } } memset(ap, 0, sizeof(*ap)); if (av_set_parameters(oc, ap) < 0) { fprintf(stderr, "%s: Invalid encoding parameters\n", oc->filename); ffmpeg_exit(1); } oc->preload= (int)(mux_preload*AV_TIME_BASE); oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE); oc->loop_output = loop_output; oc->flags |= AVFMT_FLAG_NONBLOCK; set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM, NULL); av_freep(&forced_key_frames); }
['static void opt_output_file(const char *filename)\n{\n AVFormatContext *oc;\n int err, use_video, use_audio, use_subtitle;\n int input_has_video, input_has_audio, input_has_subtitle;\n AVFormatParameters params, *ap = &params;\n AVOutputFormat *file_oformat;\n if (!strcmp(filename, "-"))\n filename = "pipe:";\n oc = avformat_alloc_context();\n if (!oc) {\n print_error(filename, AVERROR(ENOMEM));\n ffmpeg_exit(1);\n }\n if (last_asked_format) {\n file_oformat = av_guess_format(last_asked_format, NULL, NULL);\n if (!file_oformat) {\n fprintf(stderr, "Requested output format \'%s\' is not a suitable output format\\n", last_asked_format);\n ffmpeg_exit(1);\n }\n last_asked_format = NULL;\n } else {\n file_oformat = av_guess_format(NULL, filename, NULL);\n if (!file_oformat) {\n fprintf(stderr, "Unable to find a suitable output format for \'%s\'\\n",\n filename);\n ffmpeg_exit(1);\n }\n }\n oc->oformat = file_oformat;\n av_strlcpy(oc->filename, filename, sizeof(oc->filename));\n if (!strcmp(file_oformat->name, "ffm") &&\n av_strstart(filename, "http:", NULL)) {\n int err = read_ffserver_streams(oc, filename);\n if (err < 0) {\n print_error(filename, err);\n ffmpeg_exit(1);\n }\n } else {\n use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name;\n use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name;\n use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name;\n if (nb_input_files > 0) {\n check_audio_video_sub_inputs(&input_has_video, &input_has_audio,\n &input_has_subtitle);\n if (!input_has_video)\n use_video = 0;\n if (!input_has_audio)\n use_audio = 0;\n if (!input_has_subtitle)\n use_subtitle = 0;\n }\n if (audio_disable) use_audio = 0;\n if (video_disable) use_video = 0;\n if (subtitle_disable) use_subtitle = 0;\n if (use_video) new_video_stream(oc, nb_output_files);\n if (use_audio) new_audio_stream(oc, nb_output_files);\n if (use_subtitle) new_subtitle_stream(oc, nb_output_files);\n oc->timestamp = recording_timestamp;\n av_metadata_copy(&oc->metadata, metadata, 0);\n av_metadata_free(&metadata);\n }\n output_files[nb_output_files++] = oc;\n if (oc->oformat->flags & AVFMT_NEEDNUMBER) {\n if (!av_filename_number_test(oc->filename)) {\n print_error(oc->filename, AVERROR(EINVAL));\n ffmpeg_exit(1);\n }\n }\n if (!(oc->oformat->flags & AVFMT_NOFILE)) {\n if (!file_overwrite &&\n (strchr(filename, \':\') == NULL ||\n filename[1] == \':\' ||\n av_strstart(filename, "file:", NULL))) {\n if (avio_check(filename, 0) == 0) {\n if (!using_stdin) {\n fprintf(stderr,"File \'%s\' already exists. Overwrite ? [y/N] ", filename);\n fflush(stderr);\n if (!read_yesno()) {\n fprintf(stderr, "Not overwriting - exiting\\n");\n ffmpeg_exit(1);\n }\n }\n else {\n fprintf(stderr,"File \'%s\' already exists. Exiting.\\n", filename);\n ffmpeg_exit(1);\n }\n }\n }\n if ((err = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE)) < 0) {\n print_error(filename, err);\n ffmpeg_exit(1);\n }\n }\n memset(ap, 0, sizeof(*ap));\n if (av_set_parameters(oc, ap) < 0) {\n fprintf(stderr, "%s: Invalid encoding parameters\\n",\n oc->filename);\n ffmpeg_exit(1);\n }\n oc->preload= (int)(mux_preload*AV_TIME_BASE);\n oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);\n oc->loop_output = loop_output;\n oc->flags |= AVFMT_FLAG_NONBLOCK;\n set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM, NULL);\n av_freep(&forced_key_frames);\n}', 'AVFormatContext *avformat_alloc_context(void)\n{\n AVFormatContext *ic;\n ic = av_malloc(sizeof(AVFormatContext));\n if (!ic) return ic;\n avformat_get_context_defaults(ic);\n ic->av_class = &av_format_context_class;\n return ic;\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}', 'void print_error(const char *filename, int err)\n{\n char errbuf[128];\n const char *errbuf_ptr = errbuf;\n if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)\n errbuf_ptr = strerror(AVUNERROR(err));\n fprintf(stderr, "%s: %s\\n", filename, errbuf_ptr);\n}']
34,838
0
https://github.com/libav/libav/blob/e121ac634ba324a318f4a97f978dcfb48da6b735/libavcodec/mss2.c/#L483
static int mss2_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; MSS2Context *ctx = avctx->priv_data; MSS12Context *c = &ctx->c; AVFrame *frame = data; GetBitContext gb; GetByteContext gB; ArithCoder acoder; int keyframe, has_wmv9, has_mv, is_rle, is_555, ret; Rectangle wmv9rects[MAX_WMV9_RECTANGLES], *r; int used_rects = 0, i, implicit_rect = 0, av_uninit(wmv9_mask); av_assert0(FF_INPUT_BUFFER_PADDING_SIZE >= ARITH2_PADDING + (MIN_CACHE_BITS + 7) / 8); init_get_bits(&gb, buf, buf_size * 8); if (keyframe = get_bits1(&gb)) skip_bits(&gb, 7); has_wmv9 = get_bits1(&gb); has_mv = keyframe ? 0 : get_bits1(&gb); is_rle = get_bits1(&gb); is_555 = is_rle && get_bits1(&gb); if (c->slice_split > 0) ctx->split_position = c->slice_split; else if (c->slice_split < 0) { if (get_bits1(&gb)) { if (get_bits1(&gb)) { if (get_bits1(&gb)) ctx->split_position = get_bits(&gb, 16); else ctx->split_position = get_bits(&gb, 12); } else ctx->split_position = get_bits(&gb, 8) << 4; } else { if (keyframe) ctx->split_position = avctx->height / 2; } } else ctx->split_position = avctx->height; if (c->slice_split && (ctx->split_position < 1 - is_555 || ctx->split_position > avctx->height - 1)) return AVERROR_INVALIDDATA; align_get_bits(&gb); buf += get_bits_count(&gb) >> 3; buf_size -= get_bits_count(&gb) >> 3; if (buf_size < 1) return AVERROR_INVALIDDATA; if (is_555 && (has_wmv9 || has_mv || c->slice_split && ctx->split_position)) return AVERROR_INVALIDDATA; avctx->pix_fmt = is_555 ? AV_PIX_FMT_RGB555 : AV_PIX_FMT_RGB24; if (ctx->last_pic->format != avctx->pix_fmt) av_frame_unref(ctx->last_pic); if (has_wmv9) { bytestream2_init(&gB, buf, buf_size + ARITH2_PADDING); arith2_init(&acoder, &gB); implicit_rect = !arith2_get_bit(&acoder); while (arith2_get_bit(&acoder)) { if (used_rects == MAX_WMV9_RECTANGLES) return AVERROR_INVALIDDATA; r = &wmv9rects[used_rects]; if (!used_rects) r->x = arith2_get_number(&acoder, avctx->width); else r->x = arith2_get_number(&acoder, avctx->width - wmv9rects[used_rects - 1].x) + wmv9rects[used_rects - 1].x; r->y = arith2_get_number(&acoder, avctx->height); r->w = arith2_get_number(&acoder, avctx->width - r->x) + 1; r->h = arith2_get_number(&acoder, avctx->height - r->y) + 1; used_rects++; } if (implicit_rect && used_rects) { av_log(avctx, AV_LOG_ERROR, "implicit_rect && used_rects > 0\n"); return AVERROR_INVALIDDATA; } if (implicit_rect) { wmv9rects[0].x = 0; wmv9rects[0].y = 0; wmv9rects[0].w = avctx->width; wmv9rects[0].h = avctx->height; used_rects = 1; } for (i = 0; i < used_rects; i++) { if (!implicit_rect && arith2_get_bit(&acoder)) { av_log(avctx, AV_LOG_ERROR, "Unexpected grandchildren\n"); return AVERROR_INVALIDDATA; } if (!i) { wmv9_mask = arith2_get_bit(&acoder) - 1; if (!wmv9_mask) wmv9_mask = arith2_get_number(&acoder, 256); } wmv9rects[i].coded = arith2_get_number(&acoder, 2); } buf += arith2_get_consumed_bytes(&acoder); buf_size -= arith2_get_consumed_bytes(&acoder); if (buf_size < 1) return AVERROR_INVALIDDATA; } c->mvX = c->mvY = 0; if (keyframe && !is_555) { if ((i = decode_pal_v2(c, buf, buf_size)) < 0) return AVERROR_INVALIDDATA; buf += i; buf_size -= i; } else if (has_mv) { buf += 4; buf_size -= 4; if (buf_size < 1) return AVERROR_INVALIDDATA; c->mvX = AV_RB16(buf - 4) - avctx->width; c->mvY = AV_RB16(buf - 2) - avctx->height; } if (c->mvX < 0 || c->mvY < 0) { FFSWAP(uint8_t *, c->pal_pic, c->last_pal_pic); if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } if (ctx->last_pic->data[0]) { av_assert0(frame->linesize[0] == ctx->last_pic->linesize[0]); c->last_rgb_pic = ctx->last_pic->data[0] + ctx->last_pic->linesize[0] * (avctx->height - 1); } else { av_log(avctx, AV_LOG_ERROR, "Missing keyframe\n"); return AVERROR_INVALIDDATA; } } else { if ((ret = ff_reget_buffer(avctx, ctx->last_pic)) < 0) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); return ret; } if ((ret = av_frame_ref(frame, ctx->last_pic)) < 0) return ret; c->last_rgb_pic = NULL; } c->rgb_pic = frame->data[0] + frame->linesize[0] * (avctx->height - 1); c->rgb_stride = -frame->linesize[0]; frame->key_frame = keyframe; frame->pict_type = keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P; if (is_555) { bytestream2_init(&gB, buf, buf_size); if (decode_555(&gB, (uint16_t *)c->rgb_pic, c->rgb_stride >> 1, keyframe, avctx->width, avctx->height)) return AVERROR_INVALIDDATA; buf_size -= bytestream2_tell(&gB); } else { if (keyframe) { c->corrupted = 0; ff_mss12_slicecontext_reset(&ctx->sc[0]); if (c->slice_split) ff_mss12_slicecontext_reset(&ctx->sc[1]); } if (is_rle) { init_get_bits(&gb, buf, buf_size * 8); if (ret = decode_rle(&gb, c->pal_pic, c->pal_stride, c->rgb_pic, c->rgb_stride, c->pal, keyframe, ctx->split_position, 0, avctx->width, avctx->height)) return ret; align_get_bits(&gb); if (c->slice_split) if (ret = decode_rle(&gb, c->pal_pic, c->pal_stride, c->rgb_pic, c->rgb_stride, c->pal, keyframe, ctx->split_position, 1, avctx->width, avctx->height)) return ret; align_get_bits(&gb); buf += get_bits_count(&gb) >> 3; buf_size -= get_bits_count(&gb) >> 3; } else if (!implicit_rect || wmv9_mask != -1) { if (c->corrupted) return AVERROR_INVALIDDATA; bytestream2_init(&gB, buf, buf_size + ARITH2_PADDING); arith2_init(&acoder, &gB); c->keyframe = keyframe; if (c->corrupted = ff_mss12_decode_rect(&ctx->sc[0], &acoder, 0, 0, avctx->width, ctx->split_position)) return AVERROR_INVALIDDATA; buf += arith2_get_consumed_bytes(&acoder); buf_size -= arith2_get_consumed_bytes(&acoder); if (c->slice_split) { if (buf_size < 1) return AVERROR_INVALIDDATA; bytestream2_init(&gB, buf, buf_size + ARITH2_PADDING); arith2_init(&acoder, &gB); if (c->corrupted = ff_mss12_decode_rect(&ctx->sc[1], &acoder, 0, ctx->split_position, avctx->width, avctx->height - ctx->split_position)) return AVERROR_INVALIDDATA; buf += arith2_get_consumed_bytes(&acoder); buf_size -= arith2_get_consumed_bytes(&acoder); } } else memset(c->pal_pic, 0, c->pal_stride * avctx->height); } if (has_wmv9) { for (i = 0; i < used_rects; i++) { int x = wmv9rects[i].x; int y = wmv9rects[i].y; int w = wmv9rects[i].w; int h = wmv9rects[i].h; if (wmv9rects[i].coded) { int WMV9codedFrameSize; if (buf_size < 4 || !(WMV9codedFrameSize = AV_RL24(buf))) return AVERROR_INVALIDDATA; if (ret = decode_wmv9(avctx, buf + 3, buf_size - 3, x, y, w, h, wmv9_mask)) return ret; buf += WMV9codedFrameSize + 3; buf_size -= WMV9codedFrameSize + 3; } else { uint8_t *dst = c->rgb_pic + y * c->rgb_stride + x * 3; if (wmv9_mask != -1) { ctx->dsp.mss2_gray_fill_masked(dst, c->rgb_stride, wmv9_mask, c->pal_pic + y * c->pal_stride + x, c->pal_stride, w, h); } else { do { memset(dst, 0x80, w * 3); dst += c->rgb_stride; } while (--h); } } } } if (buf_size) av_log(avctx, AV_LOG_WARNING, "buffer not fully consumed\n"); if (c->mvX < 0 || c->mvY < 0) { av_frame_unref(ctx->last_pic); ret = av_frame_ref(ctx->last_pic, frame); if (ret < 0) return ret; } *got_frame = 1; return avpkt->size; }
['static int mss2_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,\n AVPacket *avpkt)\n{\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n MSS2Context *ctx = avctx->priv_data;\n MSS12Context *c = &ctx->c;\n AVFrame *frame = data;\n GetBitContext gb;\n GetByteContext gB;\n ArithCoder acoder;\n int keyframe, has_wmv9, has_mv, is_rle, is_555, ret;\n Rectangle wmv9rects[MAX_WMV9_RECTANGLES], *r;\n int used_rects = 0, i, implicit_rect = 0, av_uninit(wmv9_mask);\n av_assert0(FF_INPUT_BUFFER_PADDING_SIZE >=\n ARITH2_PADDING + (MIN_CACHE_BITS + 7) / 8);\n init_get_bits(&gb, buf, buf_size * 8);\n if (keyframe = get_bits1(&gb))\n skip_bits(&gb, 7);\n has_wmv9 = get_bits1(&gb);\n has_mv = keyframe ? 0 : get_bits1(&gb);\n is_rle = get_bits1(&gb);\n is_555 = is_rle && get_bits1(&gb);\n if (c->slice_split > 0)\n ctx->split_position = c->slice_split;\n else if (c->slice_split < 0) {\n if (get_bits1(&gb)) {\n if (get_bits1(&gb)) {\n if (get_bits1(&gb))\n ctx->split_position = get_bits(&gb, 16);\n else\n ctx->split_position = get_bits(&gb, 12);\n } else\n ctx->split_position = get_bits(&gb, 8) << 4;\n } else {\n if (keyframe)\n ctx->split_position = avctx->height / 2;\n }\n } else\n ctx->split_position = avctx->height;\n if (c->slice_split && (ctx->split_position < 1 - is_555 ||\n ctx->split_position > avctx->height - 1))\n return AVERROR_INVALIDDATA;\n align_get_bits(&gb);\n buf += get_bits_count(&gb) >> 3;\n buf_size -= get_bits_count(&gb) >> 3;\n if (buf_size < 1)\n return AVERROR_INVALIDDATA;\n if (is_555 && (has_wmv9 || has_mv || c->slice_split && ctx->split_position))\n return AVERROR_INVALIDDATA;\n avctx->pix_fmt = is_555 ? AV_PIX_FMT_RGB555 : AV_PIX_FMT_RGB24;\n if (ctx->last_pic->format != avctx->pix_fmt)\n av_frame_unref(ctx->last_pic);\n if (has_wmv9) {\n bytestream2_init(&gB, buf, buf_size + ARITH2_PADDING);\n arith2_init(&acoder, &gB);\n implicit_rect = !arith2_get_bit(&acoder);\n while (arith2_get_bit(&acoder)) {\n if (used_rects == MAX_WMV9_RECTANGLES)\n return AVERROR_INVALIDDATA;\n r = &wmv9rects[used_rects];\n if (!used_rects)\n r->x = arith2_get_number(&acoder, avctx->width);\n else\n r->x = arith2_get_number(&acoder, avctx->width -\n wmv9rects[used_rects - 1].x) +\n wmv9rects[used_rects - 1].x;\n r->y = arith2_get_number(&acoder, avctx->height);\n r->w = arith2_get_number(&acoder, avctx->width - r->x) + 1;\n r->h = arith2_get_number(&acoder, avctx->height - r->y) + 1;\n used_rects++;\n }\n if (implicit_rect && used_rects) {\n av_log(avctx, AV_LOG_ERROR, "implicit_rect && used_rects > 0\\n");\n return AVERROR_INVALIDDATA;\n }\n if (implicit_rect) {\n wmv9rects[0].x = 0;\n wmv9rects[0].y = 0;\n wmv9rects[0].w = avctx->width;\n wmv9rects[0].h = avctx->height;\n used_rects = 1;\n }\n for (i = 0; i < used_rects; i++) {\n if (!implicit_rect && arith2_get_bit(&acoder)) {\n av_log(avctx, AV_LOG_ERROR, "Unexpected grandchildren\\n");\n return AVERROR_INVALIDDATA;\n }\n if (!i) {\n wmv9_mask = arith2_get_bit(&acoder) - 1;\n if (!wmv9_mask)\n wmv9_mask = arith2_get_number(&acoder, 256);\n }\n wmv9rects[i].coded = arith2_get_number(&acoder, 2);\n }\n buf += arith2_get_consumed_bytes(&acoder);\n buf_size -= arith2_get_consumed_bytes(&acoder);\n if (buf_size < 1)\n return AVERROR_INVALIDDATA;\n }\n c->mvX = c->mvY = 0;\n if (keyframe && !is_555) {\n if ((i = decode_pal_v2(c, buf, buf_size)) < 0)\n return AVERROR_INVALIDDATA;\n buf += i;\n buf_size -= i;\n } else if (has_mv) {\n buf += 4;\n buf_size -= 4;\n if (buf_size < 1)\n return AVERROR_INVALIDDATA;\n c->mvX = AV_RB16(buf - 4) - avctx->width;\n c->mvY = AV_RB16(buf - 2) - avctx->height;\n }\n if (c->mvX < 0 || c->mvY < 0) {\n FFSWAP(uint8_t *, c->pal_pic, c->last_pal_pic);\n if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0) {\n av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\\n");\n return ret;\n }\n if (ctx->last_pic->data[0]) {\n av_assert0(frame->linesize[0] == ctx->last_pic->linesize[0]);\n c->last_rgb_pic = ctx->last_pic->data[0] +\n ctx->last_pic->linesize[0] * (avctx->height - 1);\n } else {\n av_log(avctx, AV_LOG_ERROR, "Missing keyframe\\n");\n return AVERROR_INVALIDDATA;\n }\n } else {\n if ((ret = ff_reget_buffer(avctx, ctx->last_pic)) < 0) {\n av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\\n");\n return ret;\n }\n if ((ret = av_frame_ref(frame, ctx->last_pic)) < 0)\n return ret;\n c->last_rgb_pic = NULL;\n }\n c->rgb_pic = frame->data[0] +\n frame->linesize[0] * (avctx->height - 1);\n c->rgb_stride = -frame->linesize[0];\n frame->key_frame = keyframe;\n frame->pict_type = keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;\n if (is_555) {\n bytestream2_init(&gB, buf, buf_size);\n if (decode_555(&gB, (uint16_t *)c->rgb_pic, c->rgb_stride >> 1,\n keyframe, avctx->width, avctx->height))\n return AVERROR_INVALIDDATA;\n buf_size -= bytestream2_tell(&gB);\n } else {\n if (keyframe) {\n c->corrupted = 0;\n ff_mss12_slicecontext_reset(&ctx->sc[0]);\n if (c->slice_split)\n ff_mss12_slicecontext_reset(&ctx->sc[1]);\n }\n if (is_rle) {\n init_get_bits(&gb, buf, buf_size * 8);\n if (ret = decode_rle(&gb, c->pal_pic, c->pal_stride,\n c->rgb_pic, c->rgb_stride, c->pal, keyframe,\n ctx->split_position, 0,\n avctx->width, avctx->height))\n return ret;\n align_get_bits(&gb);\n if (c->slice_split)\n if (ret = decode_rle(&gb, c->pal_pic, c->pal_stride,\n c->rgb_pic, c->rgb_stride, c->pal, keyframe,\n ctx->split_position, 1,\n avctx->width, avctx->height))\n return ret;\n align_get_bits(&gb);\n buf += get_bits_count(&gb) >> 3;\n buf_size -= get_bits_count(&gb) >> 3;\n } else if (!implicit_rect || wmv9_mask != -1) {\n if (c->corrupted)\n return AVERROR_INVALIDDATA;\n bytestream2_init(&gB, buf, buf_size + ARITH2_PADDING);\n arith2_init(&acoder, &gB);\n c->keyframe = keyframe;\n if (c->corrupted = ff_mss12_decode_rect(&ctx->sc[0], &acoder, 0, 0,\n avctx->width,\n ctx->split_position))\n return AVERROR_INVALIDDATA;\n buf += arith2_get_consumed_bytes(&acoder);\n buf_size -= arith2_get_consumed_bytes(&acoder);\n if (c->slice_split) {\n if (buf_size < 1)\n return AVERROR_INVALIDDATA;\n bytestream2_init(&gB, buf, buf_size + ARITH2_PADDING);\n arith2_init(&acoder, &gB);\n if (c->corrupted = ff_mss12_decode_rect(&ctx->sc[1], &acoder, 0,\n ctx->split_position,\n avctx->width,\n avctx->height - ctx->split_position))\n return AVERROR_INVALIDDATA;\n buf += arith2_get_consumed_bytes(&acoder);\n buf_size -= arith2_get_consumed_bytes(&acoder);\n }\n } else\n memset(c->pal_pic, 0, c->pal_stride * avctx->height);\n }\n if (has_wmv9) {\n for (i = 0; i < used_rects; i++) {\n int x = wmv9rects[i].x;\n int y = wmv9rects[i].y;\n int w = wmv9rects[i].w;\n int h = wmv9rects[i].h;\n if (wmv9rects[i].coded) {\n int WMV9codedFrameSize;\n if (buf_size < 4 || !(WMV9codedFrameSize = AV_RL24(buf)))\n return AVERROR_INVALIDDATA;\n if (ret = decode_wmv9(avctx, buf + 3, buf_size - 3,\n x, y, w, h, wmv9_mask))\n return ret;\n buf += WMV9codedFrameSize + 3;\n buf_size -= WMV9codedFrameSize + 3;\n } else {\n uint8_t *dst = c->rgb_pic + y * c->rgb_stride + x * 3;\n if (wmv9_mask != -1) {\n ctx->dsp.mss2_gray_fill_masked(dst, c->rgb_stride,\n wmv9_mask,\n c->pal_pic + y * c->pal_stride + x,\n c->pal_stride,\n w, h);\n } else {\n do {\n memset(dst, 0x80, w * 3);\n dst += c->rgb_stride;\n } while (--h);\n }\n }\n }\n }\n if (buf_size)\n av_log(avctx, AV_LOG_WARNING, "buffer not fully consumed\\n");\n if (c->mvX < 0 || c->mvY < 0) {\n av_frame_unref(ctx->last_pic);\n ret = av_frame_ref(ctx->last_pic, frame);\n if (ret < 0)\n return ret;\n }\n *got_frame = 1;\n return avpkt->size;\n}', 'static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,\n int bit_size)\n{\n int buffer_size;\n int ret = 0;\n if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n ret = AVERROR_INVALIDDATA;\n }\n buffer_size = (bit_size + 7) >> 3;\n s->buffer = buffer;\n s->size_in_bits = bit_size;\n#if !UNCHECKED_BITSTREAM_READER\n s->size_in_bits_plus8 = bit_size + 8;\n#endif\n s->buffer_end = buffer + buffer_size;\n s->index = 0;\n return ret;\n}', 'static inline unsigned int get_bits1(GetBitContext *s)\n{\n unsigned int index = s->index;\n uint8_t result = s->buffer[index >> 3];\n#ifdef BITSTREAM_READER_LE\n result >>= index & 7;\n result &= 1;\n#else\n result <<= index & 7;\n result >>= 8 - 1;\n#endif\n#if !UNCHECKED_BITSTREAM_READER\n if (s->index < s->size_in_bits_plus8)\n#endif\n index++;\n s->index = index;\n return result;\n}']
34,839
0
https://github.com/apache/httpd/blob/c40628c17214a7a7ce6b970c2acb1578cbdc1542/modules/http/http_filters.c/#L151
static apr_status_t get_remaining_chunk_line(http_ctx_t *ctx, apr_bucket_brigade *b, int linelimit) { apr_status_t rv; apr_off_t brigade_length; apr_bucket *e; const char *lineend; apr_size_t len; rv = apr_brigade_length(b, 0, &brigade_length); if (rv != APR_SUCCESS) { return rv; } if (brigade_length == -1) { return APR_EGENERAL; } if (!brigade_length) { return APR_EAGAIN; } ctx->linesize += brigade_length; if (ctx->linesize > linelimit) { return APR_ENOSPC; } for (e = APR_BRIGADE_LAST(b); e != APR_BRIGADE_SENTINEL(b); e = APR_BUCKET_PREV(e)) { if (APR_BUCKET_IS_METADATA(e)) { continue; } rv = apr_bucket_read(e, &lineend, &len, APR_BLOCK_READ); if (rv != APR_SUCCESS) { return rv; } if (len > 0) { break; } } if (!len || e == APR_BRIGADE_SENTINEL(b)) { return APR_EAGAIN; } if (lineend[len - 1] != APR_ASCII_LF) { return APR_EAGAIN; } ctx->linesize = 0; return APR_SUCCESS; }
['static apr_status_t get_remaining_chunk_line(http_ctx_t *ctx,\n apr_bucket_brigade *b,\n int linelimit)\n{\n apr_status_t rv;\n apr_off_t brigade_length;\n apr_bucket *e;\n const char *lineend;\n apr_size_t len;\n rv = apr_brigade_length(b, 0, &brigade_length);\n if (rv != APR_SUCCESS) {\n return rv;\n }\n if (brigade_length == -1) {\n return APR_EGENERAL;\n }\n if (!brigade_length) {\n return APR_EAGAIN;\n }\n ctx->linesize += brigade_length;\n if (ctx->linesize > linelimit) {\n return APR_ENOSPC;\n }\n for (e = APR_BRIGADE_LAST(b);\n e != APR_BRIGADE_SENTINEL(b);\n e = APR_BUCKET_PREV(e)) {\n if (APR_BUCKET_IS_METADATA(e)) {\n continue;\n }\n rv = apr_bucket_read(e, &lineend, &len, APR_BLOCK_READ);\n if (rv != APR_SUCCESS) {\n return rv;\n }\n if (len > 0) {\n break;\n }\n }\n if (!len || e == APR_BRIGADE_SENTINEL(b)) {\n return APR_EAGAIN;\n }\n if (lineend[len - 1] != APR_ASCII_LF) {\n return APR_EAGAIN;\n }\n ctx->linesize = 0;\n return APR_SUCCESS;\n}']
34,840
0
https://github.com/openssl/openssl/blob/d40a1b865fddc3d67f8c06ff1f1466fad331c8f7/crypto/bn/bn_lib.c/#L250
int BN_num_bits(const BIGNUM *a) { int i = a->top - 1; bn_check_top(a); if (BN_is_zero(a)) return 0; return ((i*BN_BITS2) + BN_num_bits_word(a->d[i])); }
['static void generate_zkp(JPAKE_STEP_PART *p, const BIGNUM *x,\n\t\t\t const BIGNUM *zkpg, JPAKE_CTX *ctx)\n {\n BIGNUM *r = BN_new();\n BIGNUM *h = BN_new();\n BIGNUM *t = BN_new();\n BN_rand_range(r, ctx->p.q);\n BN_mod_exp(p->zkpx.gr, zkpg, r, ctx->p.p, ctx->ctx);\n zkp_hash(h, zkpg, p, ctx->p.name);\n BN_mod_mul(t, x, h, ctx->p.q, ctx->ctx);\n BN_mod_sub(p->zkpx.b, r, t, ctx->p.q, ctx->ctx);\n BN_free(t);\n BN_free(h);\n BN_free(r);\n }', 'int\tBN_rand_range(BIGNUM *r, const BIGNUM *range)\n\t{\n\treturn bn_rand_range(0, r, range);\n\t}', 'static int bn_rand_range(int pseudo, BIGNUM *r, const BIGNUM *range)\n\t{\n\tint (*bn_rand)(BIGNUM *, size_t, int, int)\n\t = pseudo ? BN_pseudo_rand : BN_rand;\n\tint n;\n\tint count = 100;\n\tif (range->neg || BN_is_zero(range))\n\t\t{\n\t\tBNerr(BN_F_BN_RAND_RANGE, BN_R_INVALID_RANGE);\n\t\treturn 0;\n\t\t}\n\tn = BN_num_bits(range);\n\tif (n == 1)\n\t\tBN_zero(r);\n\telse if (!BN_is_bit_set(range, n - 2) && !BN_is_bit_set(range, n - 3))\n\t\t{\n\t\tdo\n\t\t\t{\n\t\t\tif (!bn_rand(r, n + 1, -1, 0)) return 0;\n\t\t\tif (BN_cmp(r ,range) >= 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_sub(r, r, range)) return 0;\n\t\t\t\tif (BN_cmp(r, range) >= 0)\n\t\t\t\t\tif (!BN_sub(r, r, range)) return 0;\n\t\t\t\t}\n\t\t\tif (!--count)\n\t\t\t\t{\n\t\t\t\tBNerr(BN_F_BN_RAND_RANGE, BN_R_TOO_MANY_ITERATIONS);\n\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\t\twhile (BN_cmp(r, range) >= 0);\n\t\t}\n\telse\n\t\t{\n\t\tdo\n\t\t\t{\n\t\t\tif (!bn_rand(r, n, -1, 0)) return 0;\n\t\t\tif (!--count)\n\t\t\t\t{\n\t\t\t\tBNerr(BN_F_BN_RAND_RANGE, BN_R_TOO_MANY_ITERATIONS);\n\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\t\twhile (BN_cmp(r, range) >= 0);\n\t\t}\n\tbn_check_top(r);\n\treturn 1;\n\t}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n\t BN_CTX *ctx)\n\t{\n\tint ret;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n\tif (BN_is_odd(m))\n\t\t{\n# ifdef MONT_EXP_WORD\n\t\tif (a->top == 1 && !a->neg && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0))\n\t\t\t{\n\t\t\tBN_ULONG A = a->d[0];\n\t\t\tret=BN_mod_exp_mont_word(r,A,p,m,ctx,NULL);\n\t\t\t}\n\t\telse\n# endif\n\t\t\tret=BN_mod_exp_mont(r,a,p,m,ctx,NULL);\n\t\t}\n\telse\n#endif\n#ifdef RECP_MUL_MOD\n\t\t{ ret=BN_mod_exp_recp(r,a,p,m,ctx); }\n#else\n\t\t{ ret=BN_mod_exp_simple(r,a,p,m,ctx); }\n#endif\n\tbn_check_top(r);\n\treturn(ret);\n\t}', 'int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n\t{\n\tBN_MONT_CTX *mont = NULL;\n\tint b, bits, ret=0;\n\tint r_is_one;\n\tBN_ULONG w, next_w;\n\tBIGNUM *d, *r, *t;\n\tBIGNUM *swap_tmp;\n#define BN_MOD_MUL_WORD(r, w, m) \\\n\t\t(BN_mul_word(r, (w)) && \\\n\t\t( \\\n\t\t\t(BN_mod(t, r, m, ctx) && (swap_tmp = r, r = t, t = swap_tmp, 1))))\n#define BN_TO_MONTGOMERY_WORD(r, w, mont) \\\n\t\t(BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx))\n\tif (BN_get_flags(p, BN_FLG_CONSTTIME) != 0)\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT_WORD,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n\t\treturn -1;\n\t\t}\n\tbn_check_top(p);\n\tbn_check_top(m);\n\tif (!BN_is_odd(m))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT_WORD,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\tif (m->top == 1)\n\t\ta %= m->d[0];\n\tbits = BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tret = BN_one(rr);\n\t\treturn ret;\n\t\t}\n\tif (a == 0)\n\t\t{\n\t\tBN_zero(rr);\n\t\tret = 1;\n\t\treturn ret;\n\t\t}\n\tBN_CTX_start(ctx);\n\td = BN_CTX_get(ctx);\n\tr = BN_CTX_get(ctx);\n\tt = BN_CTX_get(ctx);\n\tif (d == NULL || r == NULL || t == NULL) goto err;\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n\t\t{\n\t\tif ((mont = BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont, m, ctx)) goto err;\n\t\t}\n\tr_is_one = 1;\n\tw = a;\n\tfor (b = bits-2; b >= 0; b--)\n\t\t{\n\t\tnext_w = w*w;\n\t\tif ((next_w/w) != w)\n\t\t\t{\n\t\t\tif (r_is_one)\n\t\t\t\t{\n\t\t\t\tif (!BN_TO_MONTGOMERY_WORD(r, w, mont)) goto err;\n\t\t\t\tr_is_one = 0;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_MOD_MUL_WORD(r, w, m)) goto err;\n\t\t\t\t}\n\t\t\tnext_w = 1;\n\t\t\t}\n\t\tw = next_w;\n\t\tif (!r_is_one)\n\t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(r, r, r, mont, ctx)) goto err;\n\t\t\t}\n\t\tif (BN_is_bit_set(p, b))\n\t\t\t{\n\t\t\tnext_w = w*a;\n\t\t\tif ((next_w/a) != w)\n\t\t\t\t{\n\t\t\t\tif (r_is_one)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_TO_MONTGOMERY_WORD(r, w, mont)) goto err;\n\t\t\t\t\tr_is_one = 0;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_MOD_MUL_WORD(r, w, m)) goto err;\n\t\t\t\t\t}\n\t\t\t\tnext_w = a;\n\t\t\t\t}\n\t\t\tw = next_w;\n\t\t\t}\n\t\t}\n\tif (w != 1)\n\t\t{\n\t\tif (r_is_one)\n\t\t\t{\n\t\t\tif (!BN_TO_MONTGOMERY_WORD(r, w, mont)) goto err;\n\t\t\tr_is_one = 0;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_MOD_MUL_WORD(r, w, m)) goto err;\n\t\t\t}\n\t\t}\n\tif (r_is_one)\n\t\t{\n\t\tif (!BN_one(rr)) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_from_montgomery(rr, r, mont, ctx)) goto err;\n\t\t}\n\tret = 1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tBN_CTX_end(ctx);\n\tbn_check_top(rr);\n\treturn(ret);\n\t}', 'int BN_num_bits(const BIGNUM *a)\n\t{\n\tint i = a->top - 1;\n\tbn_check_top(a);\n\tif (BN_is_zero(a)) return 0;\n\treturn ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));\n\t}']
34,841
0
https://github.com/openssl/openssl/blob/e1f02308aeb124168d8a6655e5c822c3b0126260/apps/pkcs12.c/#L738
static int get_cert_chain(X509 *cert, X509_STORE *store, STACK_OF(X509) **chain) { X509_STORE_CTX *store_ctx = NULL; STACK_OF(X509) *chn = NULL; int i = 0; store_ctx = X509_STORE_CTX_new(); if (store_ctx == NULL) { i = X509_V_ERR_UNSPECIFIED; goto end; } if (!X509_STORE_CTX_init(store_ctx, store, cert, NULL)) { i = X509_V_ERR_UNSPECIFIED; goto end; } if (X509_verify_cert(store_ctx) > 0) chn = X509_STORE_CTX_get1_chain(store_ctx); else if ((i = X509_STORE_CTX_get_error(store_ctx)) == 0) i = X509_V_ERR_UNSPECIFIED; end: X509_STORE_CTX_free(store_ctx); *chain = chn; return i; }
['static int get_cert_chain(X509 *cert, X509_STORE *store,\n STACK_OF(X509) **chain)\n{\n X509_STORE_CTX *store_ctx = NULL;\n STACK_OF(X509) *chn = NULL;\n int i = 0;\n store_ctx = X509_STORE_CTX_new();\n if (store_ctx == NULL) {\n i = X509_V_ERR_UNSPECIFIED;\n goto end;\n }\n if (!X509_STORE_CTX_init(store_ctx, store, cert, NULL)) {\n i = X509_V_ERR_UNSPECIFIED;\n goto end;\n }\n if (X509_verify_cert(store_ctx) > 0)\n chn = X509_STORE_CTX_get1_chain(store_ctx);\n else if ((i = X509_STORE_CTX_get_error(store_ctx)) == 0)\n i = X509_V_ERR_UNSPECIFIED;\nend:\n X509_STORE_CTX_free(store_ctx);\n *chain = chn;\n return i;\n}', 'X509_STORE_CTX *X509_STORE_CTX_new(void)\n{\n X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));\n if (ctx == NULL) {\n X509err(X509_F_X509_STORE_CTX_NEW, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n return ctx;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx)\n{\n if (!ctx->chain)\n return NULL;\n return X509_chain_up_ref(ctx->chain);\n}', 'void X509_STORE_CTX_free(X509_STORE_CTX *ctx)\n{\n if (ctx == NULL)\n return;\n X509_STORE_CTX_cleanup(ctx);\n OPENSSL_free(ctx);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
34,842
0
https://github.com/libav/libav/blob/bb770c5b522bdd81b65ea4391579e5ebdd62a047/libavcodec/wmavoice.c/#L1207
static int check_bits_for_superframe(GetBitContext *orig_gb, WMAVoiceContext *s) { GetBitContext s_gb, *gb = &s_gb; int n, need_bits, bd_idx; const struct frame_type_desc *frame_desc; init_get_bits(gb, orig_gb->buffer, orig_gb->size_in_bits); skip_bits_long(gb, get_bits_count(orig_gb)); assert(get_bits_left(gb) == get_bits_left(orig_gb)); if (get_bits_left(gb) < 14) return 1; if (!get_bits1(gb)) return -1; if (get_bits1(gb)) skip_bits(gb, 12); if (s->has_residual_lsps) { if (get_bits_left(gb) < s->sframe_lsp_bitsize) return 1; skip_bits_long(gb, s->sframe_lsp_bitsize); } for (n = 0; n < MAX_FRAMES; n++) { int aw_idx_is_ext = 0; if (!s->has_residual_lsps) { if (get_bits_left(gb) < s->frame_lsp_bitsize) return 1; skip_bits_long(gb, s->frame_lsp_bitsize); } bd_idx = s->vbm_tree[get_vlc2(gb, frame_type_vlc.table, 6, 3)]; if (bd_idx < 0) return -1; frame_desc = &frame_descs[bd_idx]; if (frame_desc->acb_type == ACB_TYPE_ASYMMETRIC) { if (get_bits_left(gb) < s->pitch_nbits) return 1; skip_bits_long(gb, s->pitch_nbits); } if (frame_desc->fcb_type == FCB_TYPE_SILENCE) { skip_bits(gb, 8); } else if (frame_desc->fcb_type == FCB_TYPE_AW_PULSES) { int tmp = get_bits(gb, 6); if (tmp >= 0x36) { skip_bits(gb, 2); aw_idx_is_ext = 1; } } if (frame_desc->acb_type == ACB_TYPE_HAMMING) { need_bits = s->block_pitch_nbits + (frame_desc->n_blocks - 1) * s->block_delta_pitch_nbits; } else if (frame_desc->fcb_type == FCB_TYPE_AW_PULSES) { need_bits = 2 * !aw_idx_is_ext; } else need_bits = 0; need_bits += frame_desc->frame_size; if (get_bits_left(gb) < need_bits) return 1; skip_bits_long(gb, need_bits); } return 0; }
['static int check_bits_for_superframe(GetBitContext *orig_gb,\n WMAVoiceContext *s)\n{\n GetBitContext s_gb, *gb = &s_gb;\n int n, need_bits, bd_idx;\n const struct frame_type_desc *frame_desc;\n init_get_bits(gb, orig_gb->buffer, orig_gb->size_in_bits);\n skip_bits_long(gb, get_bits_count(orig_gb));\n assert(get_bits_left(gb) == get_bits_left(orig_gb));\n if (get_bits_left(gb) < 14)\n return 1;\n if (!get_bits1(gb))\n return -1;\n if (get_bits1(gb)) skip_bits(gb, 12);\n if (s->has_residual_lsps) {\n if (get_bits_left(gb) < s->sframe_lsp_bitsize)\n return 1;\n skip_bits_long(gb, s->sframe_lsp_bitsize);\n }\n for (n = 0; n < MAX_FRAMES; n++) {\n int aw_idx_is_ext = 0;\n if (!s->has_residual_lsps) {\n if (get_bits_left(gb) < s->frame_lsp_bitsize) return 1;\n skip_bits_long(gb, s->frame_lsp_bitsize);\n }\n bd_idx = s->vbm_tree[get_vlc2(gb, frame_type_vlc.table, 6, 3)];\n if (bd_idx < 0)\n return -1;\n frame_desc = &frame_descs[bd_idx];\n if (frame_desc->acb_type == ACB_TYPE_ASYMMETRIC) {\n if (get_bits_left(gb) < s->pitch_nbits)\n return 1;\n skip_bits_long(gb, s->pitch_nbits);\n }\n if (frame_desc->fcb_type == FCB_TYPE_SILENCE) {\n skip_bits(gb, 8);\n } else if (frame_desc->fcb_type == FCB_TYPE_AW_PULSES) {\n int tmp = get_bits(gb, 6);\n if (tmp >= 0x36) {\n skip_bits(gb, 2);\n aw_idx_is_ext = 1;\n }\n }\n if (frame_desc->acb_type == ACB_TYPE_HAMMING) {\n need_bits = s->block_pitch_nbits +\n (frame_desc->n_blocks - 1) * s->block_delta_pitch_nbits;\n } else if (frame_desc->fcb_type == FCB_TYPE_AW_PULSES) {\n need_bits = 2 * !aw_idx_is_ext;\n } else\n need_bits = 0;\n need_bits += frame_desc->frame_size;\n if (get_bits_left(gb) < need_bits)\n return 1;\n skip_bits_long(gb, need_bits);\n }\n return 0;\n}', 'static inline void init_get_bits(GetBitContext *s,\n const uint8_t *buffer, int bit_size)\n{\n int buffer_size= (bit_size+7)>>3;\n if(buffer_size < 0 || bit_size < 0) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n }\n s->buffer= buffer;\n s->size_in_bits= bit_size;\n s->buffer_end= buffer + buffer_size;\n#ifdef ALT_BITSTREAM_READER\n s->index=0;\n#elif defined LIBMPEG2_BITSTREAM_READER\n s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));\n s->bit_count = 16 + 8*((intptr_t)buffer&1);\n skip_bits_long(s, 0);\n#elif defined A32_BITSTREAM_READER\n s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3));\n s->bit_count = 32 + 8*((intptr_t)buffer&3);\n skip_bits_long(s, 0);\n#endif\n}', 'static inline int get_bits_count(const GetBitContext *s){\n return s->index;\n}', 'static inline void skip_bits_long(GetBitContext *s, int n){\n s->index += n;\n}', 'static inline int get_bits_left(GetBitContext *gb)\n{\n return gb->size_in_bits - get_bits_count(gb);\n}', 'static inline unsigned int get_bits1(GetBitContext *s){\n#ifdef ALT_BITSTREAM_READER\n unsigned int index= s->index;\n uint8_t result= s->buffer[ index>>3 ];\n#ifdef ALT_BITSTREAM_READER_LE\n result>>= (index&0x07);\n result&= 1;\n#else\n result<<= (index&0x07);\n result>>= 8 - 1;\n#endif\n index++;\n s->index= index;\n return result;\n#else\n return get_bits(s, 1);\n#endif\n}']
34,843
0
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/bn/bn_asm.c/#L212
void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n) { bn_check_num(n); if (n <= 0) return; for (;;) { sqr64(r[0],r[1],a[0]); if (--n == 0) break; sqr64(r[2],r[3],a[1]); if (--n == 0) break; sqr64(r[4],r[5],a[2]); if (--n == 0) break; sqr64(r[6],r[7],a[3]); if (--n == 0) break; a+=4; r+=8; } }
['int test_mod_mul(BIO *bp, BN_CTX *ctx)\n\t{\n\tBIGNUM *a,*b,*c,*d,*e;\n\tint i;\n\ta=BN_new();\n\tb=BN_new();\n\tc=BN_new();\n\td=BN_new();\n\te=BN_new();\n\tBN_rand(c,1024,0,0);\n\tfor (i=0; i<10; i++)\n\t\t{\n\t\tBN_rand(a,475+i*10,0,0);\n\t\tBN_rand(b,425+i*10,0,0);\n\t\ta->neg=rand_neg();\n\t\tb->neg=rand_neg();\n\t\tif (!BN_mod_mul(e,a,b,c,ctx))\n\t\t\t{\n\t\t\tunsigned long l;\n\t\t\twhile ((l=ERR_get_error()))\n\t\t\t\tfprintf(stderr,"ERROR:%s\\n",\n\t\t\t\t\tERR_error_string(l,NULL));\n\t\t\texit(1);\n\t\t\t}\n\t\tif (bp != NULL)\n\t\t\t{\n\t\t\tif (!results)\n\t\t\t\t{\n\t\t\t\tBN_print(bp,a);\n\t\t\t\tBIO_puts(bp," * ");\n\t\t\t\tBN_print(bp,b);\n\t\t\t\tBIO_puts(bp," % ");\n\t\t\t\tBN_print(bp,c);\n\t\t\t\tBIO_puts(bp," - ");\n\t\t\t\t}\n\t\t\tBN_print(bp,e);\n\t\t\tBIO_puts(bp,"\\n");\n\t\t\t}\n\t\t}\n\tBN_free(a);\n\tBN_free(b);\n\tBN_free(c);\n\tBN_free(d);\n\tBN_free(e);\n\treturn(1);\n\t}', 'int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)\n\t{\n\tunsigned char *buf=NULL;\n\tint ret=0,bit,bytes,mask;\n\ttime_t tim;\n\tbytes=(bits+7)/8;\n\tbit=(bits-1)%8;\n\tmask=0xff<<bit;\n\tbuf=(unsigned char *)Malloc(bytes);\n\tif (buf == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_RAND,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\ttime(&tim);\n\tRAND_seed(&tim,sizeof(tim));\n\tRAND_bytes(buf,(int)bytes);\n\tif (top)\n\t\t{\n\t\tif (bit == 0)\n\t\t\t{\n\t\t\tbuf[0]=1;\n\t\t\tbuf[1]|=0x80;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tbuf[0]|=(3<<(bit-1));\n\t\t\tbuf[0]&= ~(mask<<1);\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tbuf[0]|=(1<<bit);\n\t\tbuf[0]&= ~(mask<<1);\n\t\t}\n\tif (bottom)\n\t\tbuf[bytes-1]|=1;\n\tif (!BN_bin2bn(buf,bytes,rnd)) goto err;\n\tret=1;\nerr:\n\tif (buf != NULL)\n\t\t{\n\t\tmemset(buf,0,bytes);\n\t\tFree(buf);\n\t\t}\n\treturn(ret);\n\t}', 'int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, BIGNUM *m, BN_CTX *ctx)\n\t{\n\tBIGNUM *t;\n\tint r=0;\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(m);\n\tt= &(ctx->bn[ctx->tos++]);\n\tif (a == b)\n\t\t{ if (!BN_sqr(t,a,ctx)) goto err; }\n\telse\n\t\t{ if (!BN_mul(t,a,b,ctx)) goto err; }\n\tif (!BN_mod(ret,t,m,ctx)) goto err;\n\tr=1;\nerr:\n\tctx->tos--;\n\treturn(r);\n\t}', 'int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx)\n\t{\n\tint max,al;\n\tBIGNUM *tmp,*rr;\n#ifdef BN_COUNT\nprintf("BN_sqr %d * %d\\n",a->top,a->top);\n#endif\n\tbn_check_top(a);\n\ttmp= &(ctx->bn[ctx->tos]);\n\trr=(a != r)?r: (&ctx->bn[ctx->tos+1]);\n\tal=a->top;\n\tif (al <= 0)\n\t\t{\n\t\tr->top=0;\n\t\treturn(1);\n\t\t}\n\tmax=(al+al);\n\tif (bn_wexpand(rr,max+1) == NULL) return(0);\n\tr->neg=0;\n\tif (al == 4)\n\t\t{\n#ifndef BN_SQR_COMBA\n\t\tBN_ULONG t[8];\n\t\tbn_sqr_normal(rr->d,a->d,4,t);\n#else\n\t\tbn_sqr_comba4(rr->d,a->d);\n#endif\n\t\t}\n\telse if (al == 8)\n\t\t{\n#ifndef BN_SQR_COMBA\n\t\tBN_ULONG t[16];\n\t\tbn_sqr_normal(rr->d,a->d,8,t);\n#else\n\t\tbn_sqr_comba8(rr->d,a->d);\n#endif\n\t\t}\n\telse\n\t\t{\n#if defined(BN_RECURSION)\n\t\tif (al < BN_SQR_RECURSIVE_SIZE_NORMAL)\n\t\t\t{\n\t\t\tBN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL*2];\n\t\t\tbn_sqr_normal(rr->d,a->d,al,t);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tint j,k;\n\t\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\t\tj=1<<(j-1);\n\t\t\tk=j+j;\n\t\t\tif (al == j)\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(a,k*2) == NULL) return(0);\n\t\t\t\tif (bn_wexpand(tmp,k*2) == NULL) return(0);\n\t\t\t\tbn_sqr_recursive(rr->d,a->d,al,tmp->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(tmp,max) == NULL) return(0);\n\t\t\t\tbn_sqr_normal(rr->d,a->d,al,tmp->d);\n\t\t\t\t}\n\t\t\t}\n#else\n\t\tif (bn_wexpand(tmp,max) == NULL) return(0);\n\t\tbn_sqr_normal(rr->d,a->d,al,tmp->d);\n#endif\n\t\t}\n\trr->top=max;\n\tif ((max > 0) && (rr->d[max-1] == 0)) rr->top--;\n\tif (rr != r) BN_copy(r,rr);\n\treturn(1);\n\t}', 'void bn_sqr_normal(BN_ULONG *r, BN_ULONG *a, int n, BN_ULONG *tmp)\n\t{\n\tint i,j,max;\n\tBN_ULONG *ap,*rp;\n\tmax=n*2;\n\tap=a;\n\trp=r;\n\trp[0]=rp[max-1]=0;\n\trp++;\n\tj=n;\n\tif (--j > 0)\n\t\t{\n\t\tap++;\n\t\trp[j]=bn_mul_words(rp,ap,j,ap[-1]);\n\t\trp+=2;\n\t\t}\n\tfor (i=n-2; i>0; i--)\n\t\t{\n\t\tj--;\n\t\tap++;\n\t\trp[j]=bn_mul_add_words(rp,ap,j,ap[-1]);\n\t\trp+=2;\n\t\t}\n\tbn_add_words(r,r,r,max);\n\tbn_sqr_words(tmp,a,n);\n\tbn_add_words(r,r,tmp,max);\n\t}', 'void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n)\n {\n\tbn_check_num(n);\n\tif (n <= 0) return;\n\tfor (;;)\n\t\t{\n\t\tsqr64(r[0],r[1],a[0]);\n\t\tif (--n == 0) break;\n\t\tsqr64(r[2],r[3],a[1]);\n\t\tif (--n == 0) break;\n\t\tsqr64(r[4],r[5],a[2]);\n\t\tif (--n == 0) break;\n\t\tsqr64(r[6],r[7],a[3]);\n\t\tif (--n == 0) break;\n\t\ta+=4;\n\t\tr+=8;\n\t\t}\n\t}']
34,844
1
https://github.com/openssl/openssl/blob/d479dc1d02debddebc7bd431321ba158ada1ec65/crypto/asn1/asn1_gen.c/#L245
ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) { ASN1_TYPE *ret; tag_exp_arg asn1_tags; tag_exp_type *etmp; int i, len; unsigned char *orig_der = NULL, *new_der = NULL; unsigned char *cpy_start, *p; int cpy_len; long hdr_len; int hdr_constructed, hdr_tag, hdr_class; int r; asn1_tags.imp_tag = -1; asn1_tags.imp_class = -1; asn1_tags.format = ASN1_GEN_FORMAT_ASCII; asn1_tags.exp_count = 0; if (CONF_parse_list(str, ',', 1, asn1_cb, &asn1_tags) != 0) return NULL; if ((asn1_tags.utype == V_ASN1_SEQUENCE) || (asn1_tags.utype == V_ASN1_SET)) { if (!cnf) { ASN1err(ASN1_F_ASN1_GENERATE_V3, ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG); return NULL; } ret = asn1_multi(asn1_tags.utype, asn1_tags.str, cnf); } else ret = asn1_str2type(asn1_tags.str, asn1_tags.format, asn1_tags.utype); if (!ret) return NULL; if ((asn1_tags.imp_tag == -1) && (asn1_tags.exp_count == 0)) return ret; cpy_len = i2d_ASN1_TYPE(ret, &orig_der); ASN1_TYPE_free(ret); ret = NULL; cpy_start = orig_der; if (asn1_tags.imp_tag != -1) { r = ASN1_get_object(&cpy_start, &hdr_len, &hdr_tag, &hdr_class, cpy_len); if (r & 0x80) goto err; cpy_len -= cpy_start - orig_der; if (r & 0x1) { hdr_constructed = 2; hdr_len = 0; } else hdr_constructed = r & V_ASN1_CONSTRUCTED; len = ASN1_object_size(0, hdr_len, asn1_tags.imp_tag); } else len = cpy_len; for(i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1; i < asn1_tags.exp_count; i++, etmp--) { len += etmp->exp_pad; etmp->exp_len = len; len = ASN1_object_size(0, len, etmp->exp_tag); } new_der = OPENSSL_malloc(len); p = new_der; for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count; i++, etmp++) { ASN1_put_object(&p, etmp->exp_constructed, etmp->exp_len, etmp->exp_tag, etmp->exp_class); if (etmp->exp_pad) *p++ = 0; } if (asn1_tags.imp_tag != -1) ASN1_put_object(&p, hdr_constructed, hdr_len, asn1_tags.imp_tag, asn1_tags.imp_class); memcpy(p, cpy_start, cpy_len); p = new_der; ret = d2i_ASN1_TYPE(NULL, &p, len); err: if (orig_der) OPENSSL_free(orig_der); if (new_der) OPENSSL_free(new_der); return ret; }
["ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf)\n\t{\n\tASN1_TYPE *ret;\n\ttag_exp_arg asn1_tags;\n\ttag_exp_type *etmp;\n\tint i, len;\n\tunsigned char *orig_der = NULL, *new_der = NULL;\n\tunsigned char *cpy_start, *p;\n\tint cpy_len;\n\tlong hdr_len;\n\tint hdr_constructed, hdr_tag, hdr_class;\n\tint r;\n\tasn1_tags.imp_tag = -1;\n\tasn1_tags.imp_class = -1;\n\tasn1_tags.format = ASN1_GEN_FORMAT_ASCII;\n\tasn1_tags.exp_count = 0;\n\tif (CONF_parse_list(str, ',', 1, asn1_cb, &asn1_tags) != 0)\n\t\treturn NULL;\n\tif ((asn1_tags.utype == V_ASN1_SEQUENCE) || (asn1_tags.utype == V_ASN1_SET))\n\t\t{\n\t\tif (!cnf)\n\t\t\t{\n\t\t\tASN1err(ASN1_F_ASN1_GENERATE_V3, ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG);\n\t\t\treturn NULL;\n\t\t\t}\n\t\tret = asn1_multi(asn1_tags.utype, asn1_tags.str, cnf);\n\t\t}\n\telse\n\t\tret = asn1_str2type(asn1_tags.str, asn1_tags.format, asn1_tags.utype);\n\tif (!ret)\n\t\treturn NULL;\n\tif ((asn1_tags.imp_tag == -1) && (asn1_tags.exp_count == 0))\n\t\treturn ret;\n\tcpy_len = i2d_ASN1_TYPE(ret, &orig_der);\n\tASN1_TYPE_free(ret);\n\tret = NULL;\n\tcpy_start = orig_der;\n\tif (asn1_tags.imp_tag != -1)\n\t\t{\n\t\tr = ASN1_get_object(&cpy_start, &hdr_len, &hdr_tag, &hdr_class, cpy_len);\n\t\tif (r & 0x80)\n\t\t\tgoto err;\n\t\tcpy_len -= cpy_start - orig_der;\n\t\tif (r & 0x1)\n\t\t\t{\n\t\t\thdr_constructed = 2;\n\t\t\thdr_len = 0;\n\t\t\t}\n\t\telse\n\t\t\thdr_constructed = r & V_ASN1_CONSTRUCTED;\n\t\tlen = ASN1_object_size(0, hdr_len, asn1_tags.imp_tag);\n\t\t}\n\telse\n\t\tlen = cpy_len;\n\tfor(i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1; i < asn1_tags.exp_count; i++, etmp--)\n\t\t{\n\t\tlen += etmp->exp_pad;\n\t\tetmp->exp_len = len;\n\t\tlen = ASN1_object_size(0, len, etmp->exp_tag);\n\t\t}\n\tnew_der = OPENSSL_malloc(len);\n\tp = new_der;\n\tfor (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count; i++, etmp++)\n\t\t{\n\t\tASN1_put_object(&p, etmp->exp_constructed, etmp->exp_len,\n\t\t\t\t\tetmp->exp_tag, etmp->exp_class);\n\t\tif (etmp->exp_pad)\n\t\t\t*p++ = 0;\n\t\t}\n\tif (asn1_tags.imp_tag != -1)\n\t\tASN1_put_object(&p, hdr_constructed, hdr_len,\n\t\t\t\t\tasn1_tags.imp_tag, asn1_tags.imp_class);\n\tmemcpy(p, cpy_start, cpy_len);\n\tp = new_der;\n\tret = d2i_ASN1_TYPE(NULL, &p, len);\n\terr:\n\tif (orig_der)\n\t\tOPENSSL_free(orig_der);\n\tif (new_der)\n\t\tOPENSSL_free(new_der);\n\treturn ret;\n\t}"]
34,845
0
https://github.com/libav/libav/blob/688417399c69aadd4c287bdb0dec82ef8799011c/libavcodec/hevcdsp_template.c/#L901
PUT_HEVC_QPEL_HV(1, 1)
['QPEL(48)', 'PUT_HEVC_QPEL_HV(1, 1)']
34,846
0
https://github.com/openssl/openssl/blob/02cba628daa7fea959c561531a8a984756bdf41c/crypto/bn/bn_shift.c/#L112
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n) { int i, nw, lb, rb; BN_ULONG *t, *f; BN_ULONG l; bn_check_top(r); bn_check_top(a); if (n < 0) { BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT); return 0; } nw = n / BN_BITS2; if (bn_wexpand(r, a->top + nw + 1) == NULL) return (0); r->neg = a->neg; lb = n % BN_BITS2; rb = BN_BITS2 - lb; f = a->d; t = r->d; t[a->top + nw] = 0; if (lb == 0) for (i = a->top - 1; i >= 0; i--) t[nw + i] = f[i]; else for (i = a->top - 1; i >= 0; i--) { l = f[i]; t[nw + i + 1] |= (l >> rb) & BN_MASK2; t[nw + i] = (l << lb) & BN_MASK2; } memset(t, 0, sizeof(*t) * nw); r->top = a->top + nw + 1; bn_correct_top(r); bn_check_top(r); return (1); }
['static int file_product(STANZA *s)\n{\n BIGNUM *a = getBN(s, "A");\n BIGNUM *b = getBN(s, "B");\n BIGNUM *product = getBN(s, "Product");\n BIGNUM *ret = BN_new();\n BIGNUM *remainder = BN_new();\n BIGNUM *zero = BN_new();\n int st = 0;\n if (a == NULL || b == NULL || product == NULL || ret == NULL\n || remainder == NULL || zero == NULL)\n goto err;\n BN_zero(zero);\n if (!BN_mul(ret, a, b, ctx)\n || !equalBN("A * B", product, ret)\n || !BN_div(ret, remainder, product, a, ctx)\n || !equalBN("Product / A", b, ret)\n || !equalBN("Product % A", zero, remainder)\n || !BN_div(ret, remainder, product, b, ctx)\n || !equalBN("Product / B", a, ret)\n || !equalBN("Product % B", zero, remainder))\n goto err;\n st = 1;\nerr:\n BN_free(a);\n BN_free(b);\n BN_free(product);\n BN_free(ret);\n BN_free(remainder);\n BN_free(zero);\n return st;\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return (1);\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# if 0\n if (i == 1 && !BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)b;\n if (bn_wexpand(tmp_bn, al) == NULL)\n goto err;\n tmp_bn->d[bl] = 0;\n bl++;\n i--;\n } else if (i == -1 && !BN_get_flags(a, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)a;\n if (bn_wexpand(tmp_bn, bl) == NULL)\n goto err;\n tmp_bn->d[al] = 0;\n al++;\n i++;\n }\n if (i == 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (al == j) {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, al, t->d);\n } else {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d, al - j, j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# endif\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n bn_correct_top(rr);\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return (ret);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return (1);\n }\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (dv == NULL)\n res = BN_CTX_get(ctx);\n else\n res = dv;\n if (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return (1);\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return (0);\n}', 'int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n nw = n / BN_BITS2;\n if (bn_wexpand(r, a->top + nw + 1) == NULL)\n return (0);\n r->neg = a->neg;\n lb = n % BN_BITS2;\n rb = BN_BITS2 - lb;\n f = a->d;\n t = r->d;\n t[a->top + nw] = 0;\n if (lb == 0)\n for (i = a->top - 1; i >= 0; i--)\n t[nw + i] = f[i];\n else\n for (i = a->top - 1; i >= 0; i--) {\n l = f[i];\n t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n t[nw + i] = (l << lb) & BN_MASK2;\n }\n memset(t, 0, sizeof(*t) * nw);\n r->top = a->top + nw + 1;\n bn_correct_top(r);\n bn_check_top(r);\n return (1);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
34,847
0
https://github.com/openssl/openssl/blob/5d1c09de1f2736e1d4b1877206d08455ec75f558/crypto/bn/bn_sqr.c/#L108
void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp) { int i, j, max; const BN_ULONG *ap; BN_ULONG *rp; max = n * 2; ap = a; rp = r; rp[0] = rp[max - 1] = 0; rp++; j = n; if (--j > 0) { ap++; rp[j] = bn_mul_words(rp, ap, j, ap[-1]); rp += 2; } for (i = n - 2; i > 0; i--) { j--; ap++; rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]); rp += 2; } bn_add_words(r, r, r, max); bn_sqr_words(tmp, a, n); bn_add_words(r, r, tmp, max); }
['int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,\n const BIGNUM *a2, const BIGNUM *p2, const BIGNUM *m,\n BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n int i, j, bits, b, bits1, bits2, ret =\n 0, wpos1, wpos2, window1, window2, wvalue1, wvalue2;\n int r_is_one = 1;\n BIGNUM *d, *r;\n const BIGNUM *a_mod_m;\n BIGNUM *val1[TABLE_SIZE], *val2[TABLE_SIZE];\n BN_MONT_CTX *mont = NULL;\n bn_check_top(a1);\n bn_check_top(p1);\n bn_check_top(a2);\n bn_check_top(p2);\n bn_check_top(m);\n if (!(m->d[0] & 1)) {\n BNerr(BN_F_BN_MOD_EXP2_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n bits1 = BN_num_bits(p1);\n bits2 = BN_num_bits(p2);\n if ((bits1 == 0) && (bits2 == 0)) {\n ret = BN_one(rr);\n return ret;\n }\n bits = (bits1 > bits2) ? bits1 : bits2;\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val1[0] = BN_CTX_get(ctx);\n val2[0] = BN_CTX_get(ctx);\n if (val2[0] == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n window1 = BN_window_bits_for_exponent_size(bits1);\n window2 = BN_window_bits_for_exponent_size(bits2);\n if (a1->neg || BN_ucmp(a1, m) >= 0) {\n if (!BN_mod(val1[0], a1, m, ctx))\n goto err;\n a_mod_m = val1[0];\n } else\n a_mod_m = a1;\n if (BN_is_zero(a_mod_m)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val1[0], a_mod_m, mont, ctx))\n goto err;\n if (window1 > 1) {\n if (!BN_mod_mul_montgomery(d, val1[0], val1[0], mont, ctx))\n goto err;\n j = 1 << (window1 - 1);\n for (i = 1; i < j; i++) {\n if (((val1[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val1[i], val1[i - 1], d, mont, ctx))\n goto err;\n }\n }\n if (a2->neg || BN_ucmp(a2, m) >= 0) {\n if (!BN_mod(val2[0], a2, m, ctx))\n goto err;\n a_mod_m = val2[0];\n } else\n a_mod_m = a2;\n if (BN_is_zero(a_mod_m)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val2[0], a_mod_m, mont, ctx))\n goto err;\n if (window2 > 1) {\n if (!BN_mod_mul_montgomery(d, val2[0], val2[0], mont, ctx))\n goto err;\n j = 1 << (window2 - 1);\n for (i = 1; i < j; i++) {\n if (((val2[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val2[i], val2[i - 1], d, mont, ctx))\n goto err;\n }\n }\n r_is_one = 1;\n wvalue1 = 0;\n wvalue2 = 0;\n wpos1 = 0;\n wpos2 = 0;\n if (!BN_to_montgomery(r, BN_value_one(), mont, ctx))\n goto err;\n for (b = bits - 1; b >= 0; b--) {\n if (!r_is_one) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (!wvalue1)\n if (BN_is_bit_set(p1, b)) {\n i = b - window1 + 1;\n while (!BN_is_bit_set(p1, i))\n i++;\n wpos1 = i;\n wvalue1 = 1;\n for (i = b - 1; i >= wpos1; i--) {\n wvalue1 <<= 1;\n if (BN_is_bit_set(p1, i))\n wvalue1++;\n }\n }\n if (!wvalue2)\n if (BN_is_bit_set(p2, b)) {\n i = b - window2 + 1;\n while (!BN_is_bit_set(p2, i))\n i++;\n wpos2 = i;\n wvalue2 = 1;\n for (i = b - 1; i >= wpos2; i--) {\n wvalue2 <<= 1;\n if (BN_is_bit_set(p2, i))\n wvalue2++;\n }\n }\n if (wvalue1 && b == wpos1) {\n if (!BN_mod_mul_montgomery(r, r, val1[wvalue1 >> 1], mont, ctx))\n goto err;\n wvalue1 = 0;\n r_is_one = 0;\n }\n if (wvalue2 && b == wpos2) {\n if (!BN_mod_mul_montgomery(r, r, val2[wvalue2 >> 1], mont, ctx))\n goto err;\n wvalue2 = 0;\n r_is_one = 0;\n }\n }\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return 0;\n }\n if (dv != NULL)\n BN_zero(dv);\n return 1;\n }\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.flags = BN_FLG_STATIC_DATA;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return 0;\n}', 'int BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n return BN_mod_mul_montgomery(r, a, &(mont->RR), mont, ctx);\n}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n int ret = bn_mul_mont_fixed_top(r, a, b, mont, ctx);\n bn_correct_top(r);\n bn_check_top(r);\n return ret;\n}', 'int bn_mul_mont_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n int num = mont->N.top;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return 0;\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n r->flags |= BN_FLG_FIXED_TOP;\n return 1;\n }\n }\n#endif\n if ((a->top + b->top) > 2 * num)\n return 0;\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!BN_sqr(tmp, a, ctx))\n goto err;\n } else {\n if (!BN_mul(tmp, a, b, ctx))\n goto err;\n }\n#ifdef MONT_WORD\n if (!bn_from_montgomery_word(r, tmp, mont))\n goto err;\n#else\n if (!BN_from_montgomery(r, tmp, mont, ctx))\n goto err;\n#endif\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (rr == NULL || tmp == NULL)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n rr->top = max;\n bn_correct_top(rr);\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return ret;\n}', 'void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)\n{\n int i, j, max;\n const BN_ULONG *ap;\n BN_ULONG *rp;\n max = n * 2;\n ap = a;\n rp = r;\n rp[0] = rp[max - 1] = 0;\n rp++;\n j = n;\n if (--j > 0) {\n ap++;\n rp[j] = bn_mul_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n for (i = n - 2; i > 0; i--) {\n j--;\n ap++;\n rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n bn_add_words(r, r, r, max);\n bn_sqr_words(tmp, a, n);\n bn_add_words(r, r, tmp, max);\n}']
34,848
0
https://github.com/libav/libav/blob/50f70541d36b3ff477b63b3ec754e28ace824d8e/libavcodec/mpegaudiodec.c/#L211
static inline int l2_unscale_group(int steps, int mant, int scale_factor) { int shift, mod, val; shift = scale_factor_modshift[scale_factor]; mod = shift & 3; shift >>= 2; val = (mant - (steps >> 1)) * scale_factor_mult2[steps >> 2][mod]; if (shift > 0) val = (val + (1 << (shift - 1))) >> shift; return val; }
['static int mp_decode_layer2(MPADecodeContext *s)\n{\n int sblimit;\n const unsigned char *alloc_table;\n int table, bit_alloc_bits, i, j, ch, bound, v;\n unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT];\n unsigned char scale_code[MPA_MAX_CHANNELS][SBLIMIT];\n unsigned char scale_factors[MPA_MAX_CHANNELS][SBLIMIT][3], *sf;\n int scale, qindex, bits, steps, k, l, m, b;\n table = ff_mpa_l2_select_table(s->bit_rate / 1000, s->nb_channels,\n s->sample_rate, s->lsf);\n sblimit = ff_mpa_sblimit_table[table];\n alloc_table = ff_mpa_alloc_tables[table];\n if (s->mode == MPA_JSTEREO)\n bound = (s->mode_ext + 1) * 4;\n else\n bound = sblimit;\n dprintf(s->avctx, "bound=%d sblimit=%d\\n", bound, sblimit);\n if( bound > sblimit ) bound = sblimit;\n j = 0;\n for(i=0;i<bound;i++) {\n bit_alloc_bits = alloc_table[j];\n for(ch=0;ch<s->nb_channels;ch++) {\n bit_alloc[ch][i] = get_bits(&s->gb, bit_alloc_bits);\n }\n j += 1 << bit_alloc_bits;\n }\n for(i=bound;i<sblimit;i++) {\n bit_alloc_bits = alloc_table[j];\n v = get_bits(&s->gb, bit_alloc_bits);\n bit_alloc[0][i] = v;\n bit_alloc[1][i] = v;\n j += 1 << bit_alloc_bits;\n }\n for(i=0;i<sblimit;i++) {\n for(ch=0;ch<s->nb_channels;ch++) {\n if (bit_alloc[ch][i])\n scale_code[ch][i] = get_bits(&s->gb, 2);\n }\n }\n for(i=0;i<sblimit;i++) {\n for(ch=0;ch<s->nb_channels;ch++) {\n if (bit_alloc[ch][i]) {\n sf = scale_factors[ch][i];\n switch(scale_code[ch][i]) {\n default:\n case 0:\n sf[0] = get_bits(&s->gb, 6);\n sf[1] = get_bits(&s->gb, 6);\n sf[2] = get_bits(&s->gb, 6);\n break;\n case 2:\n sf[0] = get_bits(&s->gb, 6);\n sf[1] = sf[0];\n sf[2] = sf[0];\n break;\n case 1:\n sf[0] = get_bits(&s->gb, 6);\n sf[2] = get_bits(&s->gb, 6);\n sf[1] = sf[0];\n break;\n case 3:\n sf[0] = get_bits(&s->gb, 6);\n sf[2] = get_bits(&s->gb, 6);\n sf[1] = sf[2];\n break;\n }\n }\n }\n }\n for(k=0;k<3;k++) {\n for(l=0;l<12;l+=3) {\n j = 0;\n for(i=0;i<bound;i++) {\n bit_alloc_bits = alloc_table[j];\n for(ch=0;ch<s->nb_channels;ch++) {\n b = bit_alloc[ch][i];\n if (b) {\n scale = scale_factors[ch][i][k];\n qindex = alloc_table[j+b];\n bits = ff_mpa_quant_bits[qindex];\n if (bits < 0) {\n int v2;\n v = get_bits(&s->gb, -bits);\n v2 = division_tabs[qindex][v];\n steps = ff_mpa_quant_steps[qindex];\n s->sb_samples[ch][k * 12 + l + 0][i] =\n l2_unscale_group(steps, v2 & 15, scale);\n s->sb_samples[ch][k * 12 + l + 1][i] =\n l2_unscale_group(steps, (v2 >> 4) & 15, scale);\n s->sb_samples[ch][k * 12 + l + 2][i] =\n l2_unscale_group(steps, v2 >> 8 , scale);\n } else {\n for(m=0;m<3;m++) {\n v = get_bits(&s->gb, bits);\n v = l1_unscale(bits - 1, v, scale);\n s->sb_samples[ch][k * 12 + l + m][i] = v;\n }\n }\n } else {\n s->sb_samples[ch][k * 12 + l + 0][i] = 0;\n s->sb_samples[ch][k * 12 + l + 1][i] = 0;\n s->sb_samples[ch][k * 12 + l + 2][i] = 0;\n }\n }\n j += 1 << bit_alloc_bits;\n }\n for(i=bound;i<sblimit;i++) {\n bit_alloc_bits = alloc_table[j];\n b = bit_alloc[0][i];\n if (b) {\n int mant, scale0, scale1;\n scale0 = scale_factors[0][i][k];\n scale1 = scale_factors[1][i][k];\n qindex = alloc_table[j+b];\n bits = ff_mpa_quant_bits[qindex];\n if (bits < 0) {\n v = get_bits(&s->gb, -bits);\n steps = ff_mpa_quant_steps[qindex];\n mant = v % steps;\n v = v / steps;\n s->sb_samples[0][k * 12 + l + 0][i] =\n l2_unscale_group(steps, mant, scale0);\n s->sb_samples[1][k * 12 + l + 0][i] =\n l2_unscale_group(steps, mant, scale1);\n mant = v % steps;\n v = v / steps;\n s->sb_samples[0][k * 12 + l + 1][i] =\n l2_unscale_group(steps, mant, scale0);\n s->sb_samples[1][k * 12 + l + 1][i] =\n l2_unscale_group(steps, mant, scale1);\n s->sb_samples[0][k * 12 + l + 2][i] =\n l2_unscale_group(steps, v, scale0);\n s->sb_samples[1][k * 12 + l + 2][i] =\n l2_unscale_group(steps, v, scale1);\n } else {\n for(m=0;m<3;m++) {\n mant = get_bits(&s->gb, bits);\n s->sb_samples[0][k * 12 + l + m][i] =\n l1_unscale(bits - 1, mant, scale0);\n s->sb_samples[1][k * 12 + l + m][i] =\n l1_unscale(bits - 1, mant, scale1);\n }\n }\n } else {\n s->sb_samples[0][k * 12 + l + 0][i] = 0;\n s->sb_samples[0][k * 12 + l + 1][i] = 0;\n s->sb_samples[0][k * 12 + l + 2][i] = 0;\n s->sb_samples[1][k * 12 + l + 0][i] = 0;\n s->sb_samples[1][k * 12 + l + 1][i] = 0;\n s->sb_samples[1][k * 12 + l + 2][i] = 0;\n }\n j += 1 << bit_alloc_bits;\n }\n for(i=sblimit;i<SBLIMIT;i++) {\n for(ch=0;ch<s->nb_channels;ch++) {\n s->sb_samples[ch][k * 12 + l + 0][i] = 0;\n s->sb_samples[ch][k * 12 + l + 1][i] = 0;\n s->sb_samples[ch][k * 12 + l + 2][i] = 0;\n }\n }\n }\n }\n return 3 * 12;\n}', 'static inline int l2_unscale_group(int steps, int mant, int scale_factor)\n{\n int shift, mod, val;\n shift = scale_factor_modshift[scale_factor];\n mod = shift & 3;\n shift >>= 2;\n val = (mant - (steps >> 1)) * scale_factor_mult2[steps >> 2][mod];\n if (shift > 0)\n val = (val + (1 << (shift - 1))) >> shift;\n return val;\n}']
34,849
0
https://github.com/libav/libav/blob/47399ccdfd93d337c96c76fbf591f0e3637131ef/libavcodec/bitstream.h/#L236
static inline void skip_remaining(BitstreamContext *bc, unsigned n) { #ifdef BITSTREAM_READER_LE bc->bits >>= n; #else bc->bits <<= n; #endif bc->bits_left -= n; }
['static int decode_gop_header(IVI45DecContext *ctx, AVCodecContext *avctx)\n{\n int result, i, p, tile_size, pic_size_indx, mb_size, blk_size;\n int quant_mat, blk_size_changed = 0;\n IVIBandDesc *band, *band1, *band2;\n IVIPicConfig pic_conf;\n ctx->gop_flags = bitstream_read(&ctx->bc, 8);\n ctx->gop_hdr_size = (ctx->gop_flags & 1) ? bitstream_read(&ctx->bc, 16) : 0;\n if (ctx->gop_flags & IVI5_IS_PROTECTED)\n ctx->lock_word = bitstream_read(&ctx->bc, 32);\n tile_size = (ctx->gop_flags & 0x40) ? 64 << bitstream_read(&ctx->bc, 2) : 0;\n if (tile_size > 256) {\n av_log(avctx, AV_LOG_ERROR, "Invalid tile size: %d\\n", tile_size);\n return AVERROR_INVALIDDATA;\n }\n pic_conf.luma_bands = bitstream_read(&ctx->bc, 2) * 3 + 1;\n pic_conf.chroma_bands = bitstream_read_bit(&ctx->bc) * 3 + 1;\n ctx->is_scalable = pic_conf.luma_bands != 1 || pic_conf.chroma_bands != 1;\n if (ctx->is_scalable && (pic_conf.luma_bands != 4 || pic_conf.chroma_bands != 1)) {\n av_log(avctx, AV_LOG_ERROR, "Scalability: unsupported subdivision! Luma bands: %d, chroma bands: %d\\n",\n pic_conf.luma_bands, pic_conf.chroma_bands);\n return AVERROR_INVALIDDATA;\n }\n pic_size_indx = bitstream_read(&ctx->bc, 4);\n if (pic_size_indx == IVI5_PIC_SIZE_ESC) {\n pic_conf.pic_height = bitstream_read(&ctx->bc, 13);\n pic_conf.pic_width = bitstream_read(&ctx->bc, 13);\n } else {\n pic_conf.pic_height = ivi5_common_pic_sizes[pic_size_indx * 2 + 1] << 2;\n pic_conf.pic_width = ivi5_common_pic_sizes[pic_size_indx * 2 ] << 2;\n }\n if (ctx->gop_flags & 2) {\n avpriv_report_missing_feature(avctx, "YV12 picture format");\n return AVERROR_PATCHWELCOME;\n }\n pic_conf.chroma_height = (pic_conf.pic_height + 3) >> 2;\n pic_conf.chroma_width = (pic_conf.pic_width + 3) >> 2;\n if (!tile_size) {\n pic_conf.tile_height = pic_conf.pic_height;\n pic_conf.tile_width = pic_conf.pic_width;\n } else {\n pic_conf.tile_height = pic_conf.tile_width = tile_size;\n }\n if (ivi_pic_config_cmp(&pic_conf, &ctx->pic_conf) || ctx->gop_invalid) {\n result = ff_ivi_init_planes(ctx->planes, &pic_conf, 0);\n if (result < 0) {\n av_log(avctx, AV_LOG_ERROR, "Couldn\'t reallocate color planes!\\n");\n return result;\n }\n ctx->pic_conf = pic_conf;\n blk_size_changed = 1;\n }\n for (p = 0; p <= 1; p++) {\n for (i = 0; i < (!p ? pic_conf.luma_bands : pic_conf.chroma_bands); i++) {\n band = &ctx->planes[p].bands[i];\n band->is_halfpel = bitstream_read_bit(&ctx->bc);\n mb_size = bitstream_read_bit(&ctx->bc);\n blk_size = 8 >> bitstream_read_bit(&ctx->bc);\n mb_size = blk_size << !mb_size;\n blk_size_changed = mb_size != band->mb_size || blk_size != band->blk_size;\n if (blk_size_changed) {\n band->mb_size = mb_size;\n band->blk_size = blk_size;\n }\n if (bitstream_read_bit(&ctx->bc)) {\n avpriv_report_missing_feature(avctx, "Extended transform info");\n return AVERROR_PATCHWELCOME;\n }\n switch ((p << 2) + i) {\n case 0:\n band->inv_transform = ff_ivi_inverse_slant_8x8;\n band->dc_transform = ff_ivi_dc_slant_2d;\n band->scan = ff_zigzag_direct;\n band->transform_size = 8;\n break;\n case 1:\n band->inv_transform = ff_ivi_row_slant8;\n band->dc_transform = ff_ivi_dc_row_slant;\n band->scan = ff_ivi_vertical_scan_8x8;\n band->transform_size = 8;\n break;\n case 2:\n band->inv_transform = ff_ivi_col_slant8;\n band->dc_transform = ff_ivi_dc_col_slant;\n band->scan = ff_ivi_horizontal_scan_8x8;\n band->transform_size = 8;\n break;\n case 3:\n band->inv_transform = ff_ivi_put_pixels_8x8;\n band->dc_transform = ff_ivi_put_dc_pixel_8x8;\n band->scan = ff_ivi_horizontal_scan_8x8;\n band->transform_size = 8;\n break;\n case 4:\n band->inv_transform = ff_ivi_inverse_slant_4x4;\n band->dc_transform = ff_ivi_dc_slant_2d;\n band->scan = ff_ivi_direct_scan_4x4;\n band->transform_size = 4;\n break;\n }\n band->is_2d_trans = band->inv_transform == ff_ivi_inverse_slant_8x8 ||\n band->inv_transform == ff_ivi_inverse_slant_4x4;\n if (band->transform_size != band->blk_size)\n return AVERROR_INVALIDDATA;\n if (!p) {\n quant_mat = (pic_conf.luma_bands > 1) ? i+1 : 0;\n } else {\n quant_mat = 5;\n }\n if (band->blk_size == 8) {\n band->intra_base = &ivi5_base_quant_8x8_intra[quant_mat][0];\n band->inter_base = &ivi5_base_quant_8x8_inter[quant_mat][0];\n band->intra_scale = &ivi5_scale_quant_8x8_intra[quant_mat][0];\n band->inter_scale = &ivi5_scale_quant_8x8_inter[quant_mat][0];\n } else {\n band->intra_base = ivi5_base_quant_4x4_intra;\n band->inter_base = ivi5_base_quant_4x4_inter;\n band->intra_scale = ivi5_scale_quant_4x4_intra;\n band->inter_scale = ivi5_scale_quant_4x4_inter;\n }\n if (bitstream_read(&ctx->bc, 2)) {\n av_log(avctx, AV_LOG_ERROR, "End marker missing!\\n");\n return AVERROR_INVALIDDATA;\n }\n }\n }\n for (i = 0; i < pic_conf.chroma_bands; i++) {\n band1 = &ctx->planes[1].bands[i];\n band2 = &ctx->planes[2].bands[i];\n band2->width = band1->width;\n band2->height = band1->height;\n band2->mb_size = band1->mb_size;\n band2->blk_size = band1->blk_size;\n band2->is_halfpel = band1->is_halfpel;\n band2->intra_base = band1->intra_base;\n band2->inter_base = band1->inter_base;\n band2->intra_scale = band1->intra_scale;\n band2->inter_scale = band1->inter_scale;\n band2->scan = band1->scan;\n band2->inv_transform = band1->inv_transform;\n band2->dc_transform = band1->dc_transform;\n band2->is_2d_trans = band1->is_2d_trans;\n }\n if (blk_size_changed) {\n result = ff_ivi_init_tiles(ctx->planes, pic_conf.tile_width,\n pic_conf.tile_height);\n if (result < 0) {\n av_log(avctx, AV_LOG_ERROR,\n "Couldn\'t reallocate internal structures!\\n");\n return result;\n }\n }\n if (ctx->gop_flags & 8) {\n if (bitstream_read(&ctx->bc, 3)) {\n av_log(avctx, AV_LOG_ERROR, "Alignment bits are not zero!\\n");\n return AVERROR_INVALIDDATA;\n }\n if (bitstream_read_bit(&ctx->bc))\n bitstream_skip(&ctx->bc, 24);\n }\n bitstream_align(&ctx->bc);\n bitstream_skip(&ctx->bc, 23);\n if (bitstream_read_bit(&ctx->bc)) {\n do {\n i = bitstream_read(&ctx->bc, 16);\n } while (i & 0x8000);\n }\n bitstream_align(&ctx->bc);\n return 0;\n}', 'static inline const uint8_t *bitstream_align(BitstreamContext *bc)\n{\n unsigned n = -bitstream_tell(bc) & 7;\n if (n)\n bitstream_skip(bc, n);\n return bc->buffer + (bitstream_tell(bc) >> 3);\n}', 'static inline void bitstream_skip(BitstreamContext *bc, unsigned n)\n{\n if (n < bc->bits_left)\n skip_remaining(bc, n);\n else {\n n -= bc->bits_left;\n bc->bits = 0;\n bc->bits_left = 0;\n if (n >= 64) {\n unsigned skip = n / 8;\n n -= skip * 8;\n bc->ptr += skip;\n }\n refill_64(bc);\n if (n)\n skip_remaining(bc, n);\n }\n}', 'static inline void skip_remaining(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n bc->bits >>= n;\n#else\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n}']
34,850
0
https://github.com/openssl/openssl/blob/2864df8f9d3264e19b49a246e272fb513f4c1be3/crypto/bn/bn_ctx.c/#L342
static void BN_POOL_release(BN_POOL *p, unsigned int num) { unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE; p->used -= num; while (num--) { bn_check_top(p->current->vals + offset); if (offset == 0) { offset = BN_CTX_POOL_SIZE - 1; p->current = p->current->prev; } else offset--; } }
['int BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *yy, const BIGNUM *xx,\n const int p[], BN_CTX *ctx)\n{\n BIGNUM *field;\n int ret = 0;\n bn_check_top(yy);\n bn_check_top(xx);\n BN_CTX_start(ctx);\n if ((field = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (!BN_GF2m_arr2poly(p, field))\n goto err;\n ret = BN_GF2m_mod_div(r, yy, xx, field, ctx);\n bn_check_top(r);\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG("ENTER BN_CTX_get()", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ret->flags &= (~BN_FLG_CONSTTIME);\n ctx->used++;\n CTXDBG("LEAVE BN_CTX_get()", ctx);\n return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n if (ctx == NULL)\n return;\n CTXDBG("ENTER BN_CTX_end()", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static void BN_POOL_release(BN_POOL *p, unsigned int num)\n{\n unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;\n p->used -= num;\n while (num--) {\n bn_check_top(p->current->vals + offset);\n if (offset == 0) {\n offset = BN_CTX_POOL_SIZE - 1;\n p->current = p->current->prev;\n } else\n offset--;\n }\n}']
34,851
0
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/bn/bn_prime.c/#L204
int BN_is_prime(BIGNUM *a, int checks, void (*callback)(P_I_I_P), BN_CTX *ctx_passed, char *cb_arg) { int i,j,c2=0,ret= -1; BIGNUM *check; BN_CTX *ctx=NULL,*ctx2=NULL; BN_MONT_CTX *mont=NULL; if (!BN_is_odd(a)) return(0); if (ctx_passed != NULL) ctx=ctx_passed; else if ((ctx=BN_CTX_new()) == NULL) goto err; if ((ctx2=BN_CTX_new()) == NULL) goto err; if ((mont=BN_MONT_CTX_new()) == NULL) goto err; check= &(ctx->bn[ctx->tos++]); if (!BN_MONT_CTX_set(mont,a,ctx2)) goto err; for (i=0; i<checks; i++) { if (!BN_rand(check,BN_num_bits(a)-1,0,0)) goto err; j=witness(check,a,ctx,ctx2,mont); if (j == -1) goto err; if (j) { ret=0; goto err; } if (callback != NULL) callback(1,c2++,cb_arg); } ret=1; err: ctx->tos--; if ((ctx_passed == NULL) && (ctx != NULL)) BN_CTX_free(ctx); if (ctx2 != NULL) BN_CTX_free(ctx2); if (mont != NULL) BN_MONT_CTX_free(mont); return(ret); }
['int BN_is_prime(BIGNUM *a, int checks, void (*callback)(P_I_I_P),\n\t BN_CTX *ctx_passed, char *cb_arg)\n\t{\n\tint i,j,c2=0,ret= -1;\n\tBIGNUM *check;\n\tBN_CTX *ctx=NULL,*ctx2=NULL;\n\tBN_MONT_CTX *mont=NULL;\n\tif (!BN_is_odd(a))\n\t\treturn(0);\n\tif (ctx_passed != NULL)\n\t\tctx=ctx_passed;\n\telse\n\t\tif ((ctx=BN_CTX_new()) == NULL) goto err;\n\tif ((ctx2=BN_CTX_new()) == NULL) goto err;\n\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\tcheck= &(ctx->bn[ctx->tos++]);\n\tif (!BN_MONT_CTX_set(mont,a,ctx2)) goto err;\n\tfor (i=0; i<checks; i++)\n\t\t{\n\t\tif (!BN_rand(check,BN_num_bits(a)-1,0,0)) goto err;\n\t\tj=witness(check,a,ctx,ctx2,mont);\n\t\tif (j == -1) goto err;\n\t\tif (j)\n\t\t\t{\n\t\t\tret=0;\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (callback != NULL) callback(1,c2++,cb_arg);\n\t\t}\n\tret=1;\nerr:\n\tctx->tos--;\n\tif ((ctx_passed == NULL) && (ctx != NULL))\n\t\tBN_CTX_free(ctx);\n\tif (ctx2 != NULL)\n\t\tBN_CTX_free(ctx2);\n\tif (mont != NULL) BN_MONT_CTX_free(mont);\n\treturn(ret);\n\t}', 'BN_CTX *BN_CTX_new(void)\n\t{\n\tBN_CTX *ret;\n\tret=(BN_CTX *)Malloc(sizeof(BN_CTX));\n\tif (ret == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tBN_CTX_init(ret);\n\tret->flags=BN_FLG_MALLOCED;\n\treturn(ret);\n\t}', 'BN_MONT_CTX *BN_MONT_CTX_new(void)\n\t{\n\tBN_MONT_CTX *ret;\n\tif ((ret=(BN_MONT_CTX *)Malloc(sizeof(BN_MONT_CTX))) == NULL)\n\t\treturn(NULL);\n\tBN_MONT_CTX_init(ret);\n\tret->flags=BN_FLG_MALLOCED;\n\treturn(ret);\n\t}']
34,852
0
https://github.com/openssl/openssl/blob/ee6b68ce4c67870f9323d2a380eb949f447c56ee/test/testutil/tests.c/#L303
static char *print_mem_maybe_null(const void *s, size_t n, char outbuf[MEM_BUFFER_SIZE]) { size_t i; const unsigned char *p = (const unsigned char *)s; char *out = outbuf; int pad = 2 * n >= MEM_BUFFER_SIZE; if (s == NULL) return strcpy(outbuf, "(NULL)"); if (pad) { if ((out = OPENSSL_malloc(2 * n + 1)) == NULL) { out = outbuf; n = (MEM_BUFFER_SIZE - 4) / 2; } else { pad = 0; } } for (i = 0; i < 2 * n; ) { const unsigned char c = *p++; out[i++] = "0123456789abcdef"[c >> 4]; out[i++] = "0123456789abcdef"[c & 15]; } if (pad) { out[i++] = '.'; out[i++] = '.'; out[i++] = '.'; } out[i] = '\0'; return out; }
['static int test_rsa_pkcs1(int idx)\n{\n int ret = 0;\n RSA *key;\n unsigned char ptext[256];\n unsigned char ctext[256];\n static unsigned char ptext_ex[] = "\\x54\\x85\\x9b\\x34\\x2c\\x49\\xea\\x2a";\n unsigned char ctext_ex[256];\n int plen;\n int clen = 0;\n int num;\n plen = sizeof(ptext_ex) - 1;\n clen = rsa_setkey(&key, ctext_ex, idx);\n num = RSA_public_encrypt(plen, ptext_ex, ctext, key,\n RSA_PKCS1_PADDING);\n if (!TEST_int_eq(num, clen))\n goto err;\n num = RSA_private_decrypt(num, ctext, ptext, key, RSA_PKCS1_PADDING);\n if (!TEST_mem_eq(ptext, num, ptext_ex, plen))\n goto err;\n ret = 1;\nerr:\n RSA_free(key);\n return ret;\n}', 'int test_mem_eq(const char *file, int line, const char *st1, const char *st2,\n const void *s1, size_t n1, const void *s2, size_t n2)\n{\n char b1[MEM_BUFFER_SIZE], b2[MEM_BUFFER_SIZE];\n if (s1 == NULL && s2 == NULL)\n return 1;\n if (n1 != n2 || s1 == NULL || s2 == NULL || memcmp(s1, s2, n1) != 0) {\n char *m1 = print_mem_maybe_null(s1, n1, b1);\n char *m2 = print_mem_maybe_null(s2, n2, b2);\n test_fail_message(NULL, file, line, "memory",\n "%s %s [%zu] == %s %s [%zu]",\n st1, m1, n1, st2, m2, n2);\n if (m1 != b1)\n OPENSSL_free(m1);\n if (m2 != b2)\n OPENSSL_free(m2);\n return 0;\n }\n return 1;\n}', 'static char *print_mem_maybe_null(const void *s, size_t n,\n char outbuf[MEM_BUFFER_SIZE])\n{\n size_t i;\n const unsigned char *p = (const unsigned char *)s;\n char *out = outbuf;\n int pad = 2 * n >= MEM_BUFFER_SIZE;\n if (s == NULL)\n return strcpy(outbuf, "(NULL)");\n if (pad) {\n if ((out = OPENSSL_malloc(2 * n + 1)) == NULL) {\n out = outbuf;\n n = (MEM_BUFFER_SIZE - 4) / 2;\n } else {\n pad = 0;\n }\n }\n for (i = 0; i < 2 * n; ) {\n const unsigned char c = *p++;\n out[i++] = "0123456789abcdef"[c >> 4];\n out[i++] = "0123456789abcdef"[c & 15];\n }\n if (pad) {\n out[i++] = \'.\';\n out[i++] = \'.\';\n out[i++] = \'.\';\n }\n out[i] = \'\\0\';\n return out;\n}']
34,853
0
https://github.com/openssl/openssl/blob/ea32151f7b9353f8906188d007c6893704ac17bb/crypto/ui/ui_lib.c/#L210
int UI_dup_input_string(UI *ui, const char *prompt, int flags, char *result_buf, int minsize, int maxsize) { char *prompt_copy = NULL; if (prompt) { prompt_copy = OPENSSL_strdup(prompt); if (prompt_copy == NULL) { UIerr(UI_F_UI_DUP_INPUT_STRING, ERR_R_MALLOC_FAILURE); return 0; } } return general_allocate_string(ui, prompt_copy, 1, UIT_PROMPT, flags, result_buf, minsize, maxsize, NULL); }
['int UI_dup_input_string(UI *ui, const char *prompt, int flags,\n char *result_buf, int minsize, int maxsize)\n{\n char *prompt_copy = NULL;\n if (prompt) {\n prompt_copy = OPENSSL_strdup(prompt);\n if (prompt_copy == NULL) {\n UIerr(UI_F_UI_DUP_INPUT_STRING, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n }\n return general_allocate_string(ui, prompt_copy, 1,\n UIT_PROMPT, flags, result_buf, minsize,\n maxsize, NULL);\n}', 'char *CRYPTO_strdup(const char *str, const char* file, int line)\n{\n char *ret;\n size_t size;\n if (str == NULL)\n return NULL;\n size = strlen(str) + 1;\n ret = CRYPTO_malloc(size, file, line);\n if (ret != NULL)\n memcpy(ret, str, size);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'static int general_allocate_string(UI *ui, const char *prompt,\n int prompt_freeable,\n enum UI_string_types type, int input_flags,\n char *result_buf, int minsize, int maxsize,\n const char *test_buf)\n{\n int ret = -1;\n UI_STRING *s = general_allocate_prompt(ui, prompt, prompt_freeable,\n type, input_flags, result_buf);\n if (s) {\n if (allocate_string_stack(ui) >= 0) {\n s->_.string_data.result_minsize = minsize;\n s->_.string_data.result_maxsize = maxsize;\n s->_.string_data.test_buf = test_buf;\n ret = sk_UI_STRING_push(ui->strings, s);\n if (ret <= 0)\n ret--;\n } else\n free_string(s);\n }\n return ret;\n}']
34,854
0
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/h264pred.c/#L228
static void pred4x4_down_left_rv40_nodown_c(uint8_t *src, uint8_t *topright, int stride){ LOAD_TOP_EDGE LOAD_TOP_RIGHT_EDGE LOAD_LEFT_EDGE src[0+0*stride]=(t0 + t2 + 2*t1 + 2 + l0 + l2 + 2*l1 + 2)>>3; src[1+0*stride]= src[0+1*stride]=(t1 + t3 + 2*t2 + 2 + l1 + l3 + 2*l2 + 2)>>3; src[2+0*stride]= src[1+1*stride]= src[0+2*stride]=(t2 + t4 + 2*t3 + 2 + l2 + 3*l3 + 2)>>3; src[3+0*stride]= src[2+1*stride]= src[1+2*stride]= src[0+3*stride]=(t3 + t5 + 2*t4 + 2 + l3*4 + 2)>>3; src[3+1*stride]= src[2+2*stride]= src[1+3*stride]=(t4 + t6 + 2*t5 + 2 + l3*4 + 2)>>3; src[3+2*stride]= src[2+3*stride]=(t5 + t7 + 2*t6 + 2 + l3*4 + 2)>>3; src[3+3*stride]=(t6 + t7 + 1 + 2*l3 + 1)>>2; }
['static void pred4x4_down_left_rv40_nodown_c(uint8_t *src, uint8_t *topright, int stride){\n LOAD_TOP_EDGE\n LOAD_TOP_RIGHT_EDGE\n LOAD_LEFT_EDGE\n src[0+0*stride]=(t0 + t2 + 2*t1 + 2 + l0 + l2 + 2*l1 + 2)>>3;\n src[1+0*stride]=\n src[0+1*stride]=(t1 + t3 + 2*t2 + 2 + l1 + l3 + 2*l2 + 2)>>3;\n src[2+0*stride]=\n src[1+1*stride]=\n src[0+2*stride]=(t2 + t4 + 2*t3 + 2 + l2 + 3*l3 + 2)>>3;\n src[3+0*stride]=\n src[2+1*stride]=\n src[1+2*stride]=\n src[0+3*stride]=(t3 + t5 + 2*t4 + 2 + l3*4 + 2)>>3;\n src[3+1*stride]=\n src[2+2*stride]=\n src[1+3*stride]=(t4 + t6 + 2*t5 + 2 + l3*4 + 2)>>3;\n src[3+2*stride]=\n src[2+3*stride]=(t5 + t7 + 2*t6 + 2 + l3*4 + 2)>>3;\n src[3+3*stride]=(t6 + t7 + 1 + 2*l3 + 1)>>2;\n}']
34,855
0
https://github.com/libav/libav/blob/5150dd532b142d7032854a362228dd40142a8e94/libavcodec/mpegaudiodec.c/#L688
static void dct32(INTFLOAT *out, const INTFLOAT *tab) { INTFLOAT tmp0, tmp1; INTFLOAT val0 , val1 , val2 , val3 , val4 , val5 , val6 , val7 , val8 , val9 , val10, val11, val12, val13, val14, val15, val16, val17, val18, val19, val20, val21, val22, val23, val24, val25, val26, val27, val28, val29, val30, val31; BF0( 0, 31, COS0_0 , 1); BF0(15, 16, COS0_15, 5); BF( 0, 15, COS1_0 , 1); BF(16, 31,-COS1_0 , 1); BF0( 7, 24, COS0_7 , 1); BF0( 8, 23, COS0_8 , 1); BF( 7, 8, COS1_7 , 4); BF(23, 24,-COS1_7 , 4); BF( 0, 7, COS2_0 , 1); BF( 8, 15,-COS2_0 , 1); BF(16, 23, COS2_0 , 1); BF(24, 31,-COS2_0 , 1); BF0( 3, 28, COS0_3 , 1); BF0(12, 19, COS0_12, 2); BF( 3, 12, COS1_3 , 1); BF(19, 28,-COS1_3 , 1); BF0( 4, 27, COS0_4 , 1); BF0(11, 20, COS0_11, 2); BF( 4, 11, COS1_4 , 1); BF(20, 27,-COS1_4 , 1); BF( 3, 4, COS2_3 , 3); BF(11, 12,-COS2_3 , 3); BF(19, 20, COS2_3 , 3); BF(27, 28,-COS2_3 , 3); BF( 0, 3, COS3_0 , 1); BF( 4, 7,-COS3_0 , 1); BF( 8, 11, COS3_0 , 1); BF(12, 15,-COS3_0 , 1); BF(16, 19, COS3_0 , 1); BF(20, 23,-COS3_0 , 1); BF(24, 27, COS3_0 , 1); BF(28, 31,-COS3_0 , 1); BF0( 1, 30, COS0_1 , 1); BF0(14, 17, COS0_14, 3); BF( 1, 14, COS1_1 , 1); BF(17, 30,-COS1_1 , 1); BF0( 6, 25, COS0_6 , 1); BF0( 9, 22, COS0_9 , 1); BF( 6, 9, COS1_6 , 2); BF(22, 25,-COS1_6 , 2); BF( 1, 6, COS2_1 , 1); BF( 9, 14,-COS2_1 , 1); BF(17, 22, COS2_1 , 1); BF(25, 30,-COS2_1 , 1); BF0( 2, 29, COS0_2 , 1); BF0(13, 18, COS0_13, 3); BF( 2, 13, COS1_2 , 1); BF(18, 29,-COS1_2 , 1); BF0( 5, 26, COS0_5 , 1); BF0(10, 21, COS0_10, 1); BF( 5, 10, COS1_5 , 2); BF(21, 26,-COS1_5 , 2); BF( 2, 5, COS2_2 , 1); BF(10, 13,-COS2_2 , 1); BF(18, 21, COS2_2 , 1); BF(26, 29,-COS2_2 , 1); BF( 1, 2, COS3_1 , 2); BF( 5, 6,-COS3_1 , 2); BF( 9, 10, COS3_1 , 2); BF(13, 14,-COS3_1 , 2); BF(17, 18, COS3_1 , 2); BF(21, 22,-COS3_1 , 2); BF(25, 26, COS3_1 , 2); BF(29, 30,-COS3_1 , 2); BF1( 0, 1, 2, 3); BF2( 4, 5, 6, 7); BF1( 8, 9, 10, 11); BF2(12, 13, 14, 15); BF1(16, 17, 18, 19); BF2(20, 21, 22, 23); BF1(24, 25, 26, 27); BF2(28, 29, 30, 31); ADD( 8, 12); ADD(12, 10); ADD(10, 14); ADD(14, 9); ADD( 9, 13); ADD(13, 11); ADD(11, 15); out[ 0] = val0; out[16] = val1; out[ 8] = val2; out[24] = val3; out[ 4] = val4; out[20] = val5; out[12] = val6; out[28] = val7; out[ 2] = val8; out[18] = val9; out[10] = val10; out[26] = val11; out[ 6] = val12; out[22] = val13; out[14] = val14; out[30] = val15; ADD(24, 28); ADD(28, 26); ADD(26, 30); ADD(30, 25); ADD(25, 29); ADD(29, 27); ADD(27, 31); out[ 1] = val16 + val24; out[17] = val17 + val25; out[ 9] = val18 + val26; out[25] = val19 + val27; out[ 5] = val20 + val28; out[21] = val21 + val29; out[13] = val22 + val30; out[29] = val23 + val31; out[ 3] = val24 + val20; out[19] = val25 + val21; out[11] = val26 + val22; out[27] = val27 + val23; out[ 7] = val28 + val18; out[23] = val29 + val19; out[15] = val30 + val17; out[31] = val31; }
['static void mpc_synth(MPCContext *c, int16_t *out)\n{\n int dither_state = 0;\n int i, ch;\n OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE], *samples_ptr;\n for(ch = 0; ch < 2; ch++){\n samples_ptr = samples + ch;\n for(i = 0; i < SAMPLES_PER_BAND; i++) {\n ff_mpa_synth_filter(c->synth_buf[ch], &(c->synth_buf_offset[ch]),\n ff_mpa_synth_window, &dither_state,\n samples_ptr, 2,\n c->sb_samples[ch][i]);\n samples_ptr += 64;\n }\n }\n for(i = 0; i < MPC_FRAME_SIZE*2; i++)\n *out++=samples[i];\n}', 'void RENAME(ff_mpa_synth_filter)(MPA_INT *synth_buf_ptr, int *synth_buf_offset,\n MPA_INT *window, int *dither_state,\n OUT_INT *samples, int incr,\n INTFLOAT sb_samples[SBLIMIT])\n{\n register MPA_INT *synth_buf;\n register const MPA_INT *w, *w2, *p;\n int j, offset;\n OUT_INT *samples2;\n#if CONFIG_FLOAT\n float sum, sum2;\n#elif FRAC_BITS <= 15\n int32_t tmp[32];\n int sum, sum2;\n#else\n int64_t sum, sum2;\n#endif\n offset = *synth_buf_offset;\n synth_buf = synth_buf_ptr + offset;\n#if FRAC_BITS <= 15 && !CONFIG_FLOAT\n dct32(tmp, sb_samples);\n for(j=0;j<32;j++) {\n synth_buf[j] = av_clip_int16(tmp[j]);\n }\n#else\n dct32(synth_buf, sb_samples);\n#endif\n memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf));\n samples2 = samples + 31 * incr;\n w = window;\n w2 = window + 31;\n sum = *dither_state;\n p = synth_buf + 16;\n SUM8(MACS, sum, w, p);\n p = synth_buf + 48;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n w++;\n for(j=1;j<16;j++) {\n sum2 = 0;\n p = synth_buf + 16 + j;\n SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);\n p = synth_buf + 48 - j;\n SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n sum += sum2;\n *samples2 = round_sample(&sum);\n samples2 -= incr;\n w++;\n w2--;\n }\n p = synth_buf + 32;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n *dither_state= sum;\n offset = (offset - 32) & 511;\n *synth_buf_offset = offset;\n}', 'static void dct32(INTFLOAT *out, const INTFLOAT *tab)\n{\n INTFLOAT tmp0, tmp1;\n INTFLOAT val0 , val1 , val2 , val3 , val4 , val5 , val6 , val7 ,\n val8 , val9 , val10, val11, val12, val13, val14, val15,\n val16, val17, val18, val19, val20, val21, val22, val23,\n val24, val25, val26, val27, val28, val29, val30, val31;\n BF0( 0, 31, COS0_0 , 1);\n BF0(15, 16, COS0_15, 5);\n BF( 0, 15, COS1_0 , 1);\n BF(16, 31,-COS1_0 , 1);\n BF0( 7, 24, COS0_7 , 1);\n BF0( 8, 23, COS0_8 , 1);\n BF( 7, 8, COS1_7 , 4);\n BF(23, 24,-COS1_7 , 4);\n BF( 0, 7, COS2_0 , 1);\n BF( 8, 15,-COS2_0 , 1);\n BF(16, 23, COS2_0 , 1);\n BF(24, 31,-COS2_0 , 1);\n BF0( 3, 28, COS0_3 , 1);\n BF0(12, 19, COS0_12, 2);\n BF( 3, 12, COS1_3 , 1);\n BF(19, 28,-COS1_3 , 1);\n BF0( 4, 27, COS0_4 , 1);\n BF0(11, 20, COS0_11, 2);\n BF( 4, 11, COS1_4 , 1);\n BF(20, 27,-COS1_4 , 1);\n BF( 3, 4, COS2_3 , 3);\n BF(11, 12,-COS2_3 , 3);\n BF(19, 20, COS2_3 , 3);\n BF(27, 28,-COS2_3 , 3);\n BF( 0, 3, COS3_0 , 1);\n BF( 4, 7,-COS3_0 , 1);\n BF( 8, 11, COS3_0 , 1);\n BF(12, 15,-COS3_0 , 1);\n BF(16, 19, COS3_0 , 1);\n BF(20, 23,-COS3_0 , 1);\n BF(24, 27, COS3_0 , 1);\n BF(28, 31,-COS3_0 , 1);\n BF0( 1, 30, COS0_1 , 1);\n BF0(14, 17, COS0_14, 3);\n BF( 1, 14, COS1_1 , 1);\n BF(17, 30,-COS1_1 , 1);\n BF0( 6, 25, COS0_6 , 1);\n BF0( 9, 22, COS0_9 , 1);\n BF( 6, 9, COS1_6 , 2);\n BF(22, 25,-COS1_6 , 2);\n BF( 1, 6, COS2_1 , 1);\n BF( 9, 14,-COS2_1 , 1);\n BF(17, 22, COS2_1 , 1);\n BF(25, 30,-COS2_1 , 1);\n BF0( 2, 29, COS0_2 , 1);\n BF0(13, 18, COS0_13, 3);\n BF( 2, 13, COS1_2 , 1);\n BF(18, 29,-COS1_2 , 1);\n BF0( 5, 26, COS0_5 , 1);\n BF0(10, 21, COS0_10, 1);\n BF( 5, 10, COS1_5 , 2);\n BF(21, 26,-COS1_5 , 2);\n BF( 2, 5, COS2_2 , 1);\n BF(10, 13,-COS2_2 , 1);\n BF(18, 21, COS2_2 , 1);\n BF(26, 29,-COS2_2 , 1);\n BF( 1, 2, COS3_1 , 2);\n BF( 5, 6,-COS3_1 , 2);\n BF( 9, 10, COS3_1 , 2);\n BF(13, 14,-COS3_1 , 2);\n BF(17, 18, COS3_1 , 2);\n BF(21, 22,-COS3_1 , 2);\n BF(25, 26, COS3_1 , 2);\n BF(29, 30,-COS3_1 , 2);\n BF1( 0, 1, 2, 3);\n BF2( 4, 5, 6, 7);\n BF1( 8, 9, 10, 11);\n BF2(12, 13, 14, 15);\n BF1(16, 17, 18, 19);\n BF2(20, 21, 22, 23);\n BF1(24, 25, 26, 27);\n BF2(28, 29, 30, 31);\n ADD( 8, 12);\n ADD(12, 10);\n ADD(10, 14);\n ADD(14, 9);\n ADD( 9, 13);\n ADD(13, 11);\n ADD(11, 15);\n out[ 0] = val0;\n out[16] = val1;\n out[ 8] = val2;\n out[24] = val3;\n out[ 4] = val4;\n out[20] = val5;\n out[12] = val6;\n out[28] = val7;\n out[ 2] = val8;\n out[18] = val9;\n out[10] = val10;\n out[26] = val11;\n out[ 6] = val12;\n out[22] = val13;\n out[14] = val14;\n out[30] = val15;\n ADD(24, 28);\n ADD(28, 26);\n ADD(26, 30);\n ADD(30, 25);\n ADD(25, 29);\n ADD(29, 27);\n ADD(27, 31);\n out[ 1] = val16 + val24;\n out[17] = val17 + val25;\n out[ 9] = val18 + val26;\n out[25] = val19 + val27;\n out[ 5] = val20 + val28;\n out[21] = val21 + val29;\n out[13] = val22 + val30;\n out[29] = val23 + val31;\n out[ 3] = val24 + val20;\n out[19] = val25 + val21;\n out[11] = val26 + val22;\n out[27] = val27 + val23;\n out[ 7] = val28 + val18;\n out[23] = val29 + val19;\n out[15] = val30 + val17;\n out[31] = val31;\n}']
34,856
0
https://github.com/libav/libav/blob/0e5f33f2426dae28725b14468b61cbad052da240/libavcodec/h264.h/#L898
static void fill_decode_caches(H264Context *h, int mb_type){ MpegEncContext * const s = &h->s; int topleft_xy, top_xy, topright_xy, left_xy[2]; int topleft_type, top_type, topright_type, left_type[2]; const uint8_t * left_block= h->left_block; int i; topleft_xy = h->topleft_mb_xy ; top_xy = h->top_mb_xy ; topright_xy = h->topright_mb_xy; left_xy[0] = h->left_mb_xy[0] ; left_xy[1] = h->left_mb_xy[1] ; topleft_type = h->topleft_type ; top_type = h->top_type ; topright_type= h->topright_type ; left_type[0] = h->left_type[0] ; left_type[1] = h->left_type[1] ; if(!IS_SKIP(mb_type)){ if(IS_INTRA(mb_type)){ int type_mask= h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1; h->topleft_samples_available= h->top_samples_available= h->left_samples_available= 0xFFFF; h->topright_samples_available= 0xEEEA; if(!(top_type & type_mask)){ h->topleft_samples_available= 0xB3FF; h->top_samples_available= 0x33FF; h->topright_samples_available= 0x26EA; } if(IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[0])){ if(IS_INTERLACED(mb_type)){ if(!(left_type[0] & type_mask)){ h->topleft_samples_available&= 0xDFFF; h->left_samples_available&= 0x5FFF; } if(!(left_type[1] & type_mask)){ h->topleft_samples_available&= 0xFF5F; h->left_samples_available&= 0xFF5F; } }else{ int left_typei = h->slice_table[left_xy[0] + s->mb_stride ] == h->slice_num ? s->current_picture.mb_type[left_xy[0] + s->mb_stride] : 0; assert(left_xy[0] == left_xy[1]); if(!((left_typei & type_mask) && (left_type[0] & type_mask))){ h->topleft_samples_available&= 0xDF5F; h->left_samples_available&= 0x5F5F; } } }else{ if(!(left_type[0] & type_mask)){ h->topleft_samples_available&= 0xDF5F; h->left_samples_available&= 0x5F5F; } } if(!(topleft_type & type_mask)) h->topleft_samples_available&= 0x7FFF; if(!(topright_type & type_mask)) h->topright_samples_available&= 0xFBFF; if(IS_INTRA4x4(mb_type)){ if(IS_INTRA4x4(top_type)){ h->intra4x4_pred_mode_cache[4+8*0]= h->intra4x4_pred_mode[top_xy][4]; h->intra4x4_pred_mode_cache[5+8*0]= h->intra4x4_pred_mode[top_xy][5]; h->intra4x4_pred_mode_cache[6+8*0]= h->intra4x4_pred_mode[top_xy][6]; h->intra4x4_pred_mode_cache[7+8*0]= h->intra4x4_pred_mode[top_xy][3]; }else{ int pred; if(!(top_type & type_mask)) pred= -1; else{ pred= 2; } h->intra4x4_pred_mode_cache[4+8*0]= h->intra4x4_pred_mode_cache[5+8*0]= h->intra4x4_pred_mode_cache[6+8*0]= h->intra4x4_pred_mode_cache[7+8*0]= pred; } for(i=0; i<2; i++){ if(IS_INTRA4x4(left_type[i])){ h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[0+2*i]]; h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[1+2*i]]; }else{ int pred; if(!(left_type[i] & type_mask)) pred= -1; else{ pred= 2; } h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= pred; } } } } if(top_type){ AV_COPY32(&h->non_zero_count_cache[4+8*0], &h->non_zero_count[top_xy][4+3*8]); h->non_zero_count_cache[1+8*0]= h->non_zero_count[top_xy][1+1*8]; h->non_zero_count_cache[2+8*0]= h->non_zero_count[top_xy][2+1*8]; h->non_zero_count_cache[1+8*3]= h->non_zero_count[top_xy][1+2*8]; h->non_zero_count_cache[2+8*3]= h->non_zero_count[top_xy][2+2*8]; }else { h->non_zero_count_cache[1+8*0]= h->non_zero_count_cache[2+8*0]= h->non_zero_count_cache[1+8*3]= h->non_zero_count_cache[2+8*3]= AV_WN32A(&h->non_zero_count_cache[4+8*0], CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040); } for (i=0; i<2; i++) { if(left_type[i]){ h->non_zero_count_cache[3+8*1 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+0+2*i]]; h->non_zero_count_cache[3+8*2 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+1+2*i]]; h->non_zero_count_cache[0+8*1 + 8*i]= h->non_zero_count[left_xy[i]][left_block[8+4+2*i]]; h->non_zero_count_cache[0+8*4 + 8*i]= h->non_zero_count[left_xy[i]][left_block[8+5+2*i]]; }else{ h->non_zero_count_cache[3+8*1 + 2*8*i]= h->non_zero_count_cache[3+8*2 + 2*8*i]= h->non_zero_count_cache[0+8*1 + 8*i]= h->non_zero_count_cache[0+8*4 + 8*i]= CABAC && !IS_INTRA(mb_type) ? 0 : 64; } } if( CABAC ) { if(top_type) { h->top_cbp = h->cbp_table[top_xy]; } else if(IS_INTRA(mb_type)) { h->top_cbp = 0x1CF; } else { h->top_cbp = 0x00F; } if (left_type[0]) { h->left_cbp = h->cbp_table[left_xy[0]] & 0x1f0; } else if(IS_INTRA(mb_type)) { h->left_cbp = 0x1CF; } else { h->left_cbp = 0x00F; } if (left_type[0]) { h->left_cbp |= ((h->cbp_table[left_xy[0]]>>((left_block[0]&(~1))+1))&0x1) << 1; } if (left_type[1]) { h->left_cbp |= ((h->cbp_table[left_xy[1]]>>((left_block[2]&(~1))+1))&0x1) << 3; } } } #if 1 if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){ int list; for(list=0; list<h->list_count; list++){ if(!USES_LIST(mb_type, list)){ continue; } assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred)); h->mv_cache_clean[list]= 0; if(USES_LIST(top_type, list)){ const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride; const int b8_xy= h->mb2b8_xy[top_xy] + h->b8_stride; AV_COPY128(h->mv_cache[list][scan8[0] + 0 - 1*8], s->current_picture.motion_val[list][b_xy + 0]); h->ref_cache[list][scan8[0] + 0 - 1*8]= h->ref_cache[list][scan8[0] + 1 - 1*8]= s->current_picture.ref_index[list][b8_xy + 0]; h->ref_cache[list][scan8[0] + 2 - 1*8]= h->ref_cache[list][scan8[0] + 3 - 1*8]= s->current_picture.ref_index[list][b8_xy + 1]; }else{ AV_ZERO128(h->mv_cache[list][scan8[0] + 0 - 1*8]); AV_WN32A(&h->ref_cache[list][scan8[0] + 0 - 1*8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101); } for(i=0; i<2; i++){ int cache_idx = scan8[0] - 1 + i*2*8; if(USES_LIST(left_type[i], list)){ const int b_xy= h->mb2b_xy[left_xy[i]] + 3; const int b8_xy= h->mb2b8_xy[left_xy[i]] + 1; AV_COPY32(h->mv_cache[list][cache_idx ], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[0+i*2]]); AV_COPY32(h->mv_cache[list][cache_idx+8], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[1+i*2]]); h->ref_cache[list][cache_idx ]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[0+i*2]>>1)]; h->ref_cache[list][cache_idx+8]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[1+i*2]>>1)]; }else{ AV_ZERO32(h->mv_cache [list][cache_idx ]); AV_ZERO32(h->mv_cache [list][cache_idx+8]); h->ref_cache[list][cache_idx ]= h->ref_cache[list][cache_idx+8]= (left_type[i]) ? LIST_NOT_USED : PART_NOT_AVAILABLE; } } if(USES_LIST(topleft_type, list)){ const int b_xy = h->mb2b_xy [topleft_xy] + 3 + h->b_stride + (h->topleft_partition & 2*h->b_stride); const int b8_xy= h->mb2b8_xy[topleft_xy] + 1 + (h->topleft_partition & h->b8_stride); AV_COPY32(h->mv_cache[list][scan8[0] - 1 - 1*8], s->current_picture.motion_val[list][b_xy]); h->ref_cache[list][scan8[0] - 1 - 1*8]= s->current_picture.ref_index[list][b8_xy]; }else{ AV_ZERO32(h->mv_cache[list][scan8[0] - 1 - 1*8]); h->ref_cache[list][scan8[0] - 1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; } if(USES_LIST(topright_type, list)){ const int b_xy= h->mb2b_xy[topright_xy] + 3*h->b_stride; const int b8_xy= h->mb2b8_xy[topright_xy] + h->b8_stride; AV_COPY32(h->mv_cache[list][scan8[0] + 4 - 1*8], s->current_picture.motion_val[list][b_xy]); h->ref_cache[list][scan8[0] + 4 - 1*8]= s->current_picture.ref_index[list][b8_xy]; }else{ AV_ZERO32(h->mv_cache [list][scan8[0] + 4 - 1*8]); h->ref_cache[list][scan8[0] + 4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; } if((mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2)) && !FRAME_MBAFF) continue; if(!(mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2))) { h->ref_cache[list][scan8[5 ]+1] = h->ref_cache[list][scan8[7 ]+1] = h->ref_cache[list][scan8[13]+1] = h->ref_cache[list][scan8[4 ]] = h->ref_cache[list][scan8[12]] = PART_NOT_AVAILABLE; AV_ZERO32(h->mv_cache [list][scan8[5 ]+1]); AV_ZERO32(h->mv_cache [list][scan8[7 ]+1]); AV_ZERO32(h->mv_cache [list][scan8[13]+1]); AV_ZERO32(h->mv_cache [list][scan8[4 ]]); AV_ZERO32(h->mv_cache [list][scan8[12]]); if( CABAC ) { if(USES_LIST(top_type, list)){ const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride; AV_COPY128(h->mvd_cache[list][scan8[0] + 0 - 1*8], h->mvd_table[list][b_xy + 0]); }else{ AV_ZERO128(h->mvd_cache[list][scan8[0] + 0 - 1*8]); } if(USES_LIST(left_type[0], list)){ const int b_xy= h->mb2b_xy[left_xy[0]] + 3; AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 0*8], h->mvd_table[list][b_xy + h->b_stride*left_block[0]]); AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 1*8], h->mvd_table[list][b_xy + h->b_stride*left_block[1]]); }else{ AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 0*8]); AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 1*8]); } if(USES_LIST(left_type[1], list)){ const int b_xy= h->mb2b_xy[left_xy[1]] + 3; AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 2*8], h->mvd_table[list][b_xy + h->b_stride*left_block[2]]); AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 3*8], h->mvd_table[list][b_xy + h->b_stride*left_block[3]]); }else{ AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 2*8]); AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 3*8]); } AV_ZERO32(h->mvd_cache [list][scan8[5 ]+1]); AV_ZERO32(h->mvd_cache [list][scan8[7 ]+1]); AV_ZERO32(h->mvd_cache [list][scan8[13]+1]); AV_ZERO32(h->mvd_cache [list][scan8[4 ]]); AV_ZERO32(h->mvd_cache [list][scan8[12]]); if(h->slice_type_nos == FF_B_TYPE){ fill_rectangle(&h->direct_cache[scan8[0]], 4, 4, 8, MB_TYPE_16x16>>1, 1); if(IS_DIRECT(top_type)){ AV_WN32A(&h->direct_cache[scan8[0] - 1*8], 0x01010101*(MB_TYPE_DIRECT2>>1)); }else if(IS_8X8(top_type)){ int b8_xy = h->mb2b8_xy[top_xy] + h->b8_stride; h->direct_cache[scan8[0] + 0 - 1*8]= h->direct_table[b8_xy]; h->direct_cache[scan8[0] + 2 - 1*8]= h->direct_table[b8_xy + 1]; }else{ AV_WN32A(&h->direct_cache[scan8[0] - 1*8], 0x01010101*(MB_TYPE_16x16>>1)); } if(IS_DIRECT(left_type[0])) h->direct_cache[scan8[0] - 1 + 0*8]= MB_TYPE_DIRECT2>>1; else if(IS_8X8(left_type[0])) h->direct_cache[scan8[0] - 1 + 0*8]= h->direct_table[h->mb2b8_xy[left_xy[0]] + 1 + h->b8_stride*(left_block[0]>>1)]; else h->direct_cache[scan8[0] - 1 + 0*8]= MB_TYPE_16x16>>1; if(IS_DIRECT(left_type[1])) h->direct_cache[scan8[0] - 1 + 2*8]= MB_TYPE_DIRECT2>>1; else if(IS_8X8(left_type[1])) h->direct_cache[scan8[0] - 1 + 2*8]= h->direct_table[h->mb2b8_xy[left_xy[1]] + 1 + h->b8_stride*(left_block[2]>>1)]; else h->direct_cache[scan8[0] - 1 + 2*8]= MB_TYPE_16x16>>1; } } } if(FRAME_MBAFF){ #define MAP_MVS\ MAP_F2F(scan8[0] - 1 - 1*8, topleft_type)\ MAP_F2F(scan8[0] + 0 - 1*8, top_type)\ MAP_F2F(scan8[0] + 1 - 1*8, top_type)\ MAP_F2F(scan8[0] + 2 - 1*8, top_type)\ MAP_F2F(scan8[0] + 3 - 1*8, top_type)\ MAP_F2F(scan8[0] + 4 - 1*8, topright_type)\ MAP_F2F(scan8[0] - 1 + 0*8, left_type[0])\ MAP_F2F(scan8[0] - 1 + 1*8, left_type[0])\ MAP_F2F(scan8[0] - 1 + 2*8, left_type[1])\ MAP_F2F(scan8[0] - 1 + 3*8, left_type[1]) if(MB_FIELD){ #define MAP_F2F(idx, mb_type)\ if(!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\ h->ref_cache[list][idx] <<= 1;\ h->mv_cache[list][idx][1] /= 2;\ h->mvd_cache[list][idx][1] /= 2;\ } MAP_MVS #undef MAP_F2F }else{ #define MAP_F2F(idx, mb_type)\ if(IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\ h->ref_cache[list][idx] >>= 1;\ h->mv_cache[list][idx][1] <<= 1;\ h->mvd_cache[list][idx][1] <<= 1;\ } MAP_MVS #undef MAP_F2F } } } } #endif h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[0]); }
['int ff_h264_decode_mb_cavlc(H264Context *h){\n MpegEncContext * const s = &h->s;\n int mb_xy;\n int partition_count;\n unsigned int mb_type, cbp;\n int dct8x8_allowed= h->pps.transform_8x8_mode;\n mb_xy = h->mb_xy = s->mb_x + s->mb_y*s->mb_stride;\n tprintf(s->avctx, "pic:%d mb:%d/%d\\n", h->frame_num, s->mb_x, s->mb_y);\n cbp = 0;\n if(h->slice_type_nos != FF_I_TYPE){\n if(s->mb_skip_run==-1)\n s->mb_skip_run= get_ue_golomb(&s->gb);\n if (s->mb_skip_run--) {\n if(FRAME_MBAFF && (s->mb_y&1) == 0){\n if(s->mb_skip_run==0)\n h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&s->gb);\n }\n decode_mb_skip(h);\n return 0;\n }\n }\n if(FRAME_MBAFF){\n if( (s->mb_y&1) == 0 )\n h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&s->gb);\n }\n h->prev_mb_skipped= 0;\n mb_type= get_ue_golomb(&s->gb);\n if(h->slice_type_nos == FF_B_TYPE){\n if(mb_type < 23){\n partition_count= b_mb_type_info[mb_type].partition_count;\n mb_type= b_mb_type_info[mb_type].type;\n }else{\n mb_type -= 23;\n goto decode_intra_mb;\n }\n }else if(h->slice_type_nos == FF_P_TYPE){\n if(mb_type < 5){\n partition_count= p_mb_type_info[mb_type].partition_count;\n mb_type= p_mb_type_info[mb_type].type;\n }else{\n mb_type -= 5;\n goto decode_intra_mb;\n }\n }else{\n assert(h->slice_type_nos == FF_I_TYPE);\n if(h->slice_type == FF_SI_TYPE && mb_type)\n mb_type--;\ndecode_intra_mb:\n if(mb_type > 25){\n av_log(h->s.avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large at %d %d\\n", mb_type, av_get_pict_type_char(h->slice_type), s->mb_x, s->mb_y);\n return -1;\n }\n partition_count=0;\n cbp= i_mb_type_info[mb_type].cbp;\n h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode;\n mb_type= i_mb_type_info[mb_type].type;\n }\n if(MB_FIELD)\n mb_type |= MB_TYPE_INTERLACED;\n h->slice_table[ mb_xy ]= h->slice_num;\n if(IS_INTRA_PCM(mb_type)){\n unsigned int x;\n align_get_bits(&s->gb);\n for(x=0; x < (CHROMA ? 384 : 256); x++){\n ((uint8_t*)h->mb)[x]= get_bits(&s->gb, 8);\n }\n s->current_picture.qscale_table[mb_xy]= 0;\n memset(h->non_zero_count[mb_xy], 16, 32);\n s->current_picture.mb_type[mb_xy]= mb_type;\n return 0;\n }\n if(MB_MBAFF){\n h->ref_count[0] <<= 1;\n h->ref_count[1] <<= 1;\n }\n fill_decode_neighbors(h, mb_type);\n fill_decode_caches(h, mb_type);\n if(IS_INTRA(mb_type)){\n int pred_mode;\n if(IS_INTRA4x4(mb_type)){\n int i;\n int di = 1;\n if(dct8x8_allowed && get_bits1(&s->gb)){\n mb_type |= MB_TYPE_8x8DCT;\n di = 4;\n }\n for(i=0; i<16; i+=di){\n int mode= pred_intra_mode(h, i);\n if(!get_bits1(&s->gb)){\n const int rem_mode= get_bits(&s->gb, 3);\n mode = rem_mode + (rem_mode >= mode);\n }\n if(di==4)\n fill_rectangle( &h->intra4x4_pred_mode_cache[ scan8[i] ], 2, 2, 8, mode, 1 );\n else\n h->intra4x4_pred_mode_cache[ scan8[i] ] = mode;\n }\n ff_h264_write_back_intra_pred_mode(h);\n if( ff_h264_check_intra4x4_pred_mode(h) < 0)\n return -1;\n }else{\n h->intra16x16_pred_mode= ff_h264_check_intra_pred_mode(h, h->intra16x16_pred_mode);\n if(h->intra16x16_pred_mode < 0)\n return -1;\n }\n if(CHROMA){\n pred_mode= ff_h264_check_intra_pred_mode(h, get_ue_golomb_31(&s->gb));\n if(pred_mode < 0)\n return -1;\n h->chroma_pred_mode= pred_mode;\n }\n }else if(partition_count==4){\n int i, j, sub_partition_count[4], list, ref[2][4];\n if(h->slice_type_nos == FF_B_TYPE){\n for(i=0; i<4; i++){\n h->sub_mb_type[i]= get_ue_golomb_31(&s->gb);\n if(h->sub_mb_type[i] >=13){\n av_log(h->s.avctx, AV_LOG_ERROR, "B sub_mb_type %u out of range at %d %d\\n", h->sub_mb_type[i], s->mb_x, s->mb_y);\n return -1;\n }\n sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;\n h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type;\n }\n if( IS_DIRECT(h->sub_mb_type[0]|h->sub_mb_type[1]|h->sub_mb_type[2]|h->sub_mb_type[3])) {\n ff_h264_pred_direct_motion(h, &mb_type);\n h->ref_cache[0][scan8[4]] =\n h->ref_cache[1][scan8[4]] =\n h->ref_cache[0][scan8[12]] =\n h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;\n }\n }else{\n assert(h->slice_type_nos == FF_P_TYPE);\n for(i=0; i<4; i++){\n h->sub_mb_type[i]= get_ue_golomb_31(&s->gb);\n if(h->sub_mb_type[i] >=4){\n av_log(h->s.avctx, AV_LOG_ERROR, "P sub_mb_type %u out of range at %d %d\\n", h->sub_mb_type[i], s->mb_x, s->mb_y);\n return -1;\n }\n sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;\n h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type;\n }\n }\n for(list=0; list<h->list_count; list++){\n int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list];\n for(i=0; i<4; i++){\n if(IS_DIRECT(h->sub_mb_type[i])) continue;\n if(IS_DIR(h->sub_mb_type[i], 0, list)){\n unsigned int tmp;\n if(ref_count == 1){\n tmp= 0;\n }else if(ref_count == 2){\n tmp= get_bits1(&s->gb)^1;\n }else{\n tmp= get_ue_golomb_31(&s->gb);\n if(tmp>=ref_count){\n av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\\n", tmp);\n return -1;\n }\n }\n ref[list][i]= tmp;\n }else{\n ref[list][i] = -1;\n }\n }\n }\n if(dct8x8_allowed)\n dct8x8_allowed = get_dct8x8_allowed(h);\n for(list=0; list<h->list_count; list++){\n for(i=0; i<4; i++){\n if(IS_DIRECT(h->sub_mb_type[i])) {\n h->ref_cache[list][ scan8[4*i] ] = h->ref_cache[list][ scan8[4*i]+1 ];\n continue;\n }\n h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ]=\n h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i];\n if(IS_DIR(h->sub_mb_type[i], 0, list)){\n const int sub_mb_type= h->sub_mb_type[i];\n const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1;\n for(j=0; j<sub_partition_count[i]; j++){\n int mx, my;\n const int index= 4*i + block_width*j;\n int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ];\n pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my);\n mx += get_se_golomb(&s->gb);\n my += get_se_golomb(&s->gb);\n tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n if(IS_SUB_8X8(sub_mb_type)){\n mv_cache[ 1 ][0]=\n mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;\n mv_cache[ 1 ][1]=\n mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;\n }else if(IS_SUB_8X4(sub_mb_type)){\n mv_cache[ 1 ][0]= mx;\n mv_cache[ 1 ][1]= my;\n }else if(IS_SUB_4X8(sub_mb_type)){\n mv_cache[ 8 ][0]= mx;\n mv_cache[ 8 ][1]= my;\n }\n mv_cache[ 0 ][0]= mx;\n mv_cache[ 0 ][1]= my;\n }\n }else{\n uint32_t *p= (uint32_t *)&h->mv_cache[list][ scan8[4*i] ][0];\n p[0] = p[1]=\n p[8] = p[9]= 0;\n }\n }\n }\n }else if(IS_DIRECT(mb_type)){\n ff_h264_pred_direct_motion(h, &mb_type);\n dct8x8_allowed &= h->sps.direct_8x8_inference_flag;\n }else{\n int list, mx, my, i;\n if(IS_16X16(mb_type)){\n for(list=0; list<h->list_count; list++){\n unsigned int val;\n if(IS_DIR(mb_type, 0, list)){\n if(h->ref_count[list]==1){\n val= 0;\n }else if(h->ref_count[list]==2){\n val= get_bits1(&s->gb)^1;\n }else{\n val= get_ue_golomb_31(&s->gb);\n if(val >= h->ref_count[list]){\n av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\\n", val);\n return -1;\n }\n }\n }else\n val= LIST_NOT_USED&0xFF;\n fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, val, 1);\n }\n for(list=0; list<h->list_count; list++){\n unsigned int val;\n if(IS_DIR(mb_type, 0, list)){\n pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my);\n mx += get_se_golomb(&s->gb);\n my += get_se_golomb(&s->gb);\n tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n val= pack16to32(mx,my);\n }else\n val=0;\n fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, val, 4);\n }\n }\n else if(IS_16X8(mb_type)){\n for(list=0; list<h->list_count; list++){\n for(i=0; i<2; i++){\n unsigned int val;\n if(IS_DIR(mb_type, i, list)){\n if(h->ref_count[list] == 1){\n val= 0;\n }else if(h->ref_count[list] == 2){\n val= get_bits1(&s->gb)^1;\n }else{\n val= get_ue_golomb_31(&s->gb);\n if(val >= h->ref_count[list]){\n av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\\n", val);\n return -1;\n }\n }\n }else\n val= LIST_NOT_USED&0xFF;\n fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 1);\n }\n }\n for(list=0; list<h->list_count; list++){\n for(i=0; i<2; i++){\n unsigned int val;\n if(IS_DIR(mb_type, i, list)){\n pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my);\n mx += get_se_golomb(&s->gb);\n my += get_se_golomb(&s->gb);\n tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n val= pack16to32(mx,my);\n }else\n val=0;\n fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 4);\n }\n }\n }else{\n assert(IS_8X16(mb_type));\n for(list=0; list<h->list_count; list++){\n for(i=0; i<2; i++){\n unsigned int val;\n if(IS_DIR(mb_type, i, list)){\n if(h->ref_count[list]==1){\n val= 0;\n }else if(h->ref_count[list]==2){\n val= get_bits1(&s->gb)^1;\n }else{\n val= get_ue_golomb_31(&s->gb);\n if(val >= h->ref_count[list]){\n av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\\n", val);\n return -1;\n }\n }\n }else\n val= LIST_NOT_USED&0xFF;\n fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 1);\n }\n }\n for(list=0; list<h->list_count; list++){\n for(i=0; i<2; i++){\n unsigned int val;\n if(IS_DIR(mb_type, i, list)){\n pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my);\n mx += get_se_golomb(&s->gb);\n my += get_se_golomb(&s->gb);\n tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n val= pack16to32(mx,my);\n }else\n val=0;\n fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 4);\n }\n }\n }\n }\n if(IS_INTER(mb_type))\n write_back_motion(h, mb_type);\n if(!IS_INTRA16x16(mb_type)){\n cbp= get_ue_golomb(&s->gb);\n if(cbp > 47){\n av_log(h->s.avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\\n", cbp, s->mb_x, s->mb_y);\n return -1;\n }\n if(CHROMA){\n if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp[cbp];\n else cbp= golomb_to_inter_cbp [cbp];\n }else{\n if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp_gray[cbp];\n else cbp= golomb_to_inter_cbp_gray[cbp];\n }\n }\n if(dct8x8_allowed && (cbp&15) && !IS_INTRA(mb_type)){\n mb_type |= MB_TYPE_8x8DCT*get_bits1(&s->gb);\n }\n h->cbp=\n h->cbp_table[mb_xy]= cbp;\n s->current_picture.mb_type[mb_xy]= mb_type;\n if(cbp || IS_INTRA16x16(mb_type)){\n int i8x8, i4x4, chroma_idx;\n int dquant;\n GetBitContext *gb= IS_INTRA(mb_type) ? h->intra_gb_ptr : h->inter_gb_ptr;\n const uint8_t *scan, *scan8x8, *dc_scan;\n if(IS_INTERLACED(mb_type)){\n scan8x8= s->qscale ? h->field_scan8x8_cavlc : h->field_scan8x8_cavlc_q0;\n scan= s->qscale ? h->field_scan : h->field_scan_q0;\n dc_scan= luma_dc_field_scan;\n }else{\n scan8x8= s->qscale ? h->zigzag_scan8x8_cavlc : h->zigzag_scan8x8_cavlc_q0;\n scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0;\n dc_scan= luma_dc_zigzag_scan;\n }\n dquant= get_se_golomb(&s->gb);\n s->qscale += dquant;\n if(((unsigned)s->qscale) > 51){\n if(s->qscale<0) s->qscale+= 52;\n else s->qscale-= 52;\n if(((unsigned)s->qscale) > 51){\n av_log(h->s.avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\\n", dquant, s->mb_x, s->mb_y);\n return -1;\n }\n }\n h->chroma_qp[0]= get_chroma_qp(h, 0, s->qscale);\n h->chroma_qp[1]= get_chroma_qp(h, 1, s->qscale);\n if(IS_INTRA16x16(mb_type)){\n if( decode_residual(h, h->intra_gb_ptr, h->mb, LUMA_DC_BLOCK_INDEX, dc_scan, h->dequant4_coeff[0][s->qscale], 16) < 0){\n return -1;\n }\n assert((cbp&15) == 0 || (cbp&15) == 15);\n if(cbp&15){\n for(i8x8=0; i8x8<4; i8x8++){\n for(i4x4=0; i4x4<4; i4x4++){\n const int index= i4x4 + 4*i8x8;\n if( decode_residual(h, h->intra_gb_ptr, h->mb + 16*index, index, scan + 1, h->dequant4_coeff[0][s->qscale], 15) < 0 ){\n return -1;\n }\n }\n }\n }else{\n fill_rectangle(&h->non_zero_count_cache[scan8[0]], 4, 4, 8, 0, 1);\n }\n }else{\n for(i8x8=0; i8x8<4; i8x8++){\n if(cbp & (1<<i8x8)){\n if(IS_8x8DCT(mb_type)){\n DCTELEM *buf = &h->mb[64*i8x8];\n uint8_t *nnz;\n for(i4x4=0; i4x4<4; i4x4++){\n if( decode_residual(h, gb, buf, i4x4+4*i8x8, scan8x8+16*i4x4,\n h->dequant8_coeff[IS_INTRA( mb_type ) ? 0:1][s->qscale], 16) <0 )\n return -1;\n }\n nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ];\n nnz[0] += nnz[1] + nnz[8] + nnz[9];\n }else{\n for(i4x4=0; i4x4<4; i4x4++){\n const int index= i4x4 + 4*i8x8;\n if( decode_residual(h, gb, h->mb + 16*index, index, scan, h->dequant4_coeff[IS_INTRA( mb_type ) ? 0:3][s->qscale], 16) <0 ){\n return -1;\n }\n }\n }\n }else{\n uint8_t * const nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ];\n nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0;\n }\n }\n }\n if(cbp&0x30){\n for(chroma_idx=0; chroma_idx<2; chroma_idx++)\n if( decode_residual(h, gb, h->mb + 256 + 16*4*chroma_idx, CHROMA_DC_BLOCK_INDEX, chroma_dc_scan, NULL, 4) < 0){\n return -1;\n }\n }\n if(cbp&0x20){\n for(chroma_idx=0; chroma_idx<2; chroma_idx++){\n const uint32_t *qmul = h->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[chroma_idx]];\n for(i4x4=0; i4x4<4; i4x4++){\n const int index= 16 + 4*chroma_idx + i4x4;\n if( decode_residual(h, gb, h->mb + 16*index, index, scan + 1, qmul, 15) < 0){\n return -1;\n }\n }\n }\n }else{\n uint8_t * const nnz= &h->non_zero_count_cache[0];\n nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] =\n nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0;\n }\n }else{\n uint8_t * const nnz= &h->non_zero_count_cache[0];\n fill_rectangle(&nnz[scan8[0]], 4, 4, 8, 0, 1);\n nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] =\n nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0;\n }\n s->current_picture.qscale_table[mb_xy]= s->qscale;\n write_back_non_zero_count(h);\n if(MB_MBAFF){\n h->ref_count[0] >>= 1;\n h->ref_count[1] >>= 1;\n }\n return 0;\n}', 'static void fill_decode_neighbors(H264Context *h, int mb_type){\n MpegEncContext * const s = &h->s;\n const int mb_xy= h->mb_xy;\n int topleft_xy, top_xy, topright_xy, left_xy[2];\n static const uint8_t left_block_options[4][16]={\n {0,1,2,3,7,10,8,11,7+0*8, 7+1*8, 7+2*8, 7+3*8, 2+0*8, 2+3*8, 2+1*8, 2+2*8},\n {2,2,3,3,8,11,8,11,7+2*8, 7+2*8, 7+3*8, 7+3*8, 2+1*8, 2+2*8, 2+1*8, 2+2*8},\n {0,0,1,1,7,10,7,10,7+0*8, 7+0*8, 7+1*8, 7+1*8, 2+0*8, 2+3*8, 2+0*8, 2+3*8},\n {0,2,0,2,7,10,7,10,7+0*8, 7+2*8, 7+0*8, 7+2*8, 2+0*8, 2+3*8, 2+0*8, 2+3*8}\n };\n h->topleft_partition= -1;\n top_xy = mb_xy - (s->mb_stride << MB_FIELD);\n topleft_xy = top_xy - 1;\n topright_xy= top_xy + 1;\n left_xy[1] = left_xy[0] = mb_xy-1;\n h->left_block = left_block_options[0];\n if(FRAME_MBAFF){\n const int left_mb_field_flag = IS_INTERLACED(s->current_picture.mb_type[mb_xy-1]);\n const int curr_mb_field_flag = IS_INTERLACED(mb_type);\n if(s->mb_y&1){\n if (left_mb_field_flag != curr_mb_field_flag) {\n left_xy[1] = left_xy[0] = mb_xy - s->mb_stride - 1;\n if (curr_mb_field_flag) {\n left_xy[1] += s->mb_stride;\n h->left_block = left_block_options[3];\n } else {\n topleft_xy += s->mb_stride;\n h->topleft_partition = 0;\n h->left_block = left_block_options[1];\n }\n }\n }else{\n if(curr_mb_field_flag){\n topleft_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy - 1]>>7)&1)-1);\n topright_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy + 1]>>7)&1)-1);\n top_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy ]>>7)&1)-1);\n }\n if (left_mb_field_flag != curr_mb_field_flag) {\n left_xy[1] = left_xy[0] = mb_xy - 1;\n if (curr_mb_field_flag) {\n left_xy[1] += s->mb_stride;\n h->left_block = left_block_options[3];\n } else {\n h->left_block = left_block_options[2];\n }\n }\n }\n }\n h->topleft_mb_xy = topleft_xy;\n h->top_mb_xy = top_xy;\n h->topright_mb_xy= topright_xy;\n h->left_mb_xy[0] = left_xy[0];\n h->left_mb_xy[1] = left_xy[1];\n h->topleft_type = h->slice_table[topleft_xy ] == h->slice_num ? s->current_picture.mb_type[topleft_xy] : 0;\n h->top_type = h->slice_table[top_xy ] == h->slice_num ? s->current_picture.mb_type[top_xy] : 0;\n h->topright_type= h->slice_table[topright_xy] == h->slice_num ? s->current_picture.mb_type[topright_xy]: 0;\n h->left_type[0] = h->slice_table[left_xy[0] ] == h->slice_num ? s->current_picture.mb_type[left_xy[0]] : 0;\n h->left_type[1] = h->slice_table[left_xy[1] ] == h->slice_num ? s->current_picture.mb_type[left_xy[1]] : 0;\n}', 'static void fill_decode_caches(H264Context *h, int mb_type){\n MpegEncContext * const s = &h->s;\n int topleft_xy, top_xy, topright_xy, left_xy[2];\n int topleft_type, top_type, topright_type, left_type[2];\n const uint8_t * left_block= h->left_block;\n int i;\n topleft_xy = h->topleft_mb_xy ;\n top_xy = h->top_mb_xy ;\n topright_xy = h->topright_mb_xy;\n left_xy[0] = h->left_mb_xy[0] ;\n left_xy[1] = h->left_mb_xy[1] ;\n topleft_type = h->topleft_type ;\n top_type = h->top_type ;\n topright_type= h->topright_type ;\n left_type[0] = h->left_type[0] ;\n left_type[1] = h->left_type[1] ;\n if(!IS_SKIP(mb_type)){\n if(IS_INTRA(mb_type)){\n int type_mask= h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1;\n h->topleft_samples_available=\n h->top_samples_available=\n h->left_samples_available= 0xFFFF;\n h->topright_samples_available= 0xEEEA;\n if(!(top_type & type_mask)){\n h->topleft_samples_available= 0xB3FF;\n h->top_samples_available= 0x33FF;\n h->topright_samples_available= 0x26EA;\n }\n if(IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[0])){\n if(IS_INTERLACED(mb_type)){\n if(!(left_type[0] & type_mask)){\n h->topleft_samples_available&= 0xDFFF;\n h->left_samples_available&= 0x5FFF;\n }\n if(!(left_type[1] & type_mask)){\n h->topleft_samples_available&= 0xFF5F;\n h->left_samples_available&= 0xFF5F;\n }\n }else{\n int left_typei = h->slice_table[left_xy[0] + s->mb_stride ] == h->slice_num\n ? s->current_picture.mb_type[left_xy[0] + s->mb_stride] : 0;\n assert(left_xy[0] == left_xy[1]);\n if(!((left_typei & type_mask) && (left_type[0] & type_mask))){\n h->topleft_samples_available&= 0xDF5F;\n h->left_samples_available&= 0x5F5F;\n }\n }\n }else{\n if(!(left_type[0] & type_mask)){\n h->topleft_samples_available&= 0xDF5F;\n h->left_samples_available&= 0x5F5F;\n }\n }\n if(!(topleft_type & type_mask))\n h->topleft_samples_available&= 0x7FFF;\n if(!(topright_type & type_mask))\n h->topright_samples_available&= 0xFBFF;\n if(IS_INTRA4x4(mb_type)){\n if(IS_INTRA4x4(top_type)){\n h->intra4x4_pred_mode_cache[4+8*0]= h->intra4x4_pred_mode[top_xy][4];\n h->intra4x4_pred_mode_cache[5+8*0]= h->intra4x4_pred_mode[top_xy][5];\n h->intra4x4_pred_mode_cache[6+8*0]= h->intra4x4_pred_mode[top_xy][6];\n h->intra4x4_pred_mode_cache[7+8*0]= h->intra4x4_pred_mode[top_xy][3];\n }else{\n int pred;\n if(!(top_type & type_mask))\n pred= -1;\n else{\n pred= 2;\n }\n h->intra4x4_pred_mode_cache[4+8*0]=\n h->intra4x4_pred_mode_cache[5+8*0]=\n h->intra4x4_pred_mode_cache[6+8*0]=\n h->intra4x4_pred_mode_cache[7+8*0]= pred;\n }\n for(i=0; i<2; i++){\n if(IS_INTRA4x4(left_type[i])){\n h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[0+2*i]];\n h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[1+2*i]];\n }else{\n int pred;\n if(!(left_type[i] & type_mask))\n pred= -1;\n else{\n pred= 2;\n }\n h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]=\n h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= pred;\n }\n }\n }\n }\n if(top_type){\n AV_COPY32(&h->non_zero_count_cache[4+8*0], &h->non_zero_count[top_xy][4+3*8]);\n h->non_zero_count_cache[1+8*0]= h->non_zero_count[top_xy][1+1*8];\n h->non_zero_count_cache[2+8*0]= h->non_zero_count[top_xy][2+1*8];\n h->non_zero_count_cache[1+8*3]= h->non_zero_count[top_xy][1+2*8];\n h->non_zero_count_cache[2+8*3]= h->non_zero_count[top_xy][2+2*8];\n }else {\n h->non_zero_count_cache[1+8*0]=\n h->non_zero_count_cache[2+8*0]=\n h->non_zero_count_cache[1+8*3]=\n h->non_zero_count_cache[2+8*3]=\n AV_WN32A(&h->non_zero_count_cache[4+8*0], CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040);\n }\n for (i=0; i<2; i++) {\n if(left_type[i]){\n h->non_zero_count_cache[3+8*1 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+0+2*i]];\n h->non_zero_count_cache[3+8*2 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+1+2*i]];\n h->non_zero_count_cache[0+8*1 + 8*i]= h->non_zero_count[left_xy[i]][left_block[8+4+2*i]];\n h->non_zero_count_cache[0+8*4 + 8*i]= h->non_zero_count[left_xy[i]][left_block[8+5+2*i]];\n }else{\n h->non_zero_count_cache[3+8*1 + 2*8*i]=\n h->non_zero_count_cache[3+8*2 + 2*8*i]=\n h->non_zero_count_cache[0+8*1 + 8*i]=\n h->non_zero_count_cache[0+8*4 + 8*i]= CABAC && !IS_INTRA(mb_type) ? 0 : 64;\n }\n }\n if( CABAC ) {\n if(top_type) {\n h->top_cbp = h->cbp_table[top_xy];\n } else if(IS_INTRA(mb_type)) {\n h->top_cbp = 0x1CF;\n } else {\n h->top_cbp = 0x00F;\n }\n if (left_type[0]) {\n h->left_cbp = h->cbp_table[left_xy[0]] & 0x1f0;\n } else if(IS_INTRA(mb_type)) {\n h->left_cbp = 0x1CF;\n } else {\n h->left_cbp = 0x00F;\n }\n if (left_type[0]) {\n h->left_cbp |= ((h->cbp_table[left_xy[0]]>>((left_block[0]&(~1))+1))&0x1) << 1;\n }\n if (left_type[1]) {\n h->left_cbp |= ((h->cbp_table[left_xy[1]]>>((left_block[2]&(~1))+1))&0x1) << 3;\n }\n }\n }\n#if 1\n if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){\n int list;\n for(list=0; list<h->list_count; list++){\n if(!USES_LIST(mb_type, list)){\n continue;\n }\n assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred));\n h->mv_cache_clean[list]= 0;\n if(USES_LIST(top_type, list)){\n const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride;\n const int b8_xy= h->mb2b8_xy[top_xy] + h->b8_stride;\n AV_COPY128(h->mv_cache[list][scan8[0] + 0 - 1*8], s->current_picture.motion_val[list][b_xy + 0]);\n h->ref_cache[list][scan8[0] + 0 - 1*8]=\n h->ref_cache[list][scan8[0] + 1 - 1*8]= s->current_picture.ref_index[list][b8_xy + 0];\n h->ref_cache[list][scan8[0] + 2 - 1*8]=\n h->ref_cache[list][scan8[0] + 3 - 1*8]= s->current_picture.ref_index[list][b8_xy + 1];\n }else{\n AV_ZERO128(h->mv_cache[list][scan8[0] + 0 - 1*8]);\n AV_WN32A(&h->ref_cache[list][scan8[0] + 0 - 1*8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101);\n }\n for(i=0; i<2; i++){\n int cache_idx = scan8[0] - 1 + i*2*8;\n if(USES_LIST(left_type[i], list)){\n const int b_xy= h->mb2b_xy[left_xy[i]] + 3;\n const int b8_xy= h->mb2b8_xy[left_xy[i]] + 1;\n AV_COPY32(h->mv_cache[list][cache_idx ], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[0+i*2]]);\n AV_COPY32(h->mv_cache[list][cache_idx+8], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[1+i*2]]);\n h->ref_cache[list][cache_idx ]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[0+i*2]>>1)];\n h->ref_cache[list][cache_idx+8]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[1+i*2]>>1)];\n }else{\n AV_ZERO32(h->mv_cache [list][cache_idx ]);\n AV_ZERO32(h->mv_cache [list][cache_idx+8]);\n h->ref_cache[list][cache_idx ]=\n h->ref_cache[list][cache_idx+8]= (left_type[i]) ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n }\n if(USES_LIST(topleft_type, list)){\n const int b_xy = h->mb2b_xy [topleft_xy] + 3 + h->b_stride + (h->topleft_partition & 2*h->b_stride);\n const int b8_xy= h->mb2b8_xy[topleft_xy] + 1 + (h->topleft_partition & h->b8_stride);\n AV_COPY32(h->mv_cache[list][scan8[0] - 1 - 1*8], s->current_picture.motion_val[list][b_xy]);\n h->ref_cache[list][scan8[0] - 1 - 1*8]= s->current_picture.ref_index[list][b8_xy];\n }else{\n AV_ZERO32(h->mv_cache[list][scan8[0] - 1 - 1*8]);\n h->ref_cache[list][scan8[0] - 1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n if(USES_LIST(topright_type, list)){\n const int b_xy= h->mb2b_xy[topright_xy] + 3*h->b_stride;\n const int b8_xy= h->mb2b8_xy[topright_xy] + h->b8_stride;\n AV_COPY32(h->mv_cache[list][scan8[0] + 4 - 1*8], s->current_picture.motion_val[list][b_xy]);\n h->ref_cache[list][scan8[0] + 4 - 1*8]= s->current_picture.ref_index[list][b8_xy];\n }else{\n AV_ZERO32(h->mv_cache [list][scan8[0] + 4 - 1*8]);\n h->ref_cache[list][scan8[0] + 4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n if((mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2)) && !FRAME_MBAFF)\n continue;\n if(!(mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2))) {\n h->ref_cache[list][scan8[5 ]+1] =\n h->ref_cache[list][scan8[7 ]+1] =\n h->ref_cache[list][scan8[13]+1] =\n h->ref_cache[list][scan8[4 ]] =\n h->ref_cache[list][scan8[12]] = PART_NOT_AVAILABLE;\n AV_ZERO32(h->mv_cache [list][scan8[5 ]+1]);\n AV_ZERO32(h->mv_cache [list][scan8[7 ]+1]);\n AV_ZERO32(h->mv_cache [list][scan8[13]+1]);\n AV_ZERO32(h->mv_cache [list][scan8[4 ]]);\n AV_ZERO32(h->mv_cache [list][scan8[12]]);\n if( CABAC ) {\n if(USES_LIST(top_type, list)){\n const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride;\n AV_COPY128(h->mvd_cache[list][scan8[0] + 0 - 1*8], h->mvd_table[list][b_xy + 0]);\n }else{\n AV_ZERO128(h->mvd_cache[list][scan8[0] + 0 - 1*8]);\n }\n if(USES_LIST(left_type[0], list)){\n const int b_xy= h->mb2b_xy[left_xy[0]] + 3;\n AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 0*8], h->mvd_table[list][b_xy + h->b_stride*left_block[0]]);\n AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 1*8], h->mvd_table[list][b_xy + h->b_stride*left_block[1]]);\n }else{\n AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 0*8]);\n AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 1*8]);\n }\n if(USES_LIST(left_type[1], list)){\n const int b_xy= h->mb2b_xy[left_xy[1]] + 3;\n AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 2*8], h->mvd_table[list][b_xy + h->b_stride*left_block[2]]);\n AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 3*8], h->mvd_table[list][b_xy + h->b_stride*left_block[3]]);\n }else{\n AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 2*8]);\n AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 3*8]);\n }\n AV_ZERO32(h->mvd_cache [list][scan8[5 ]+1]);\n AV_ZERO32(h->mvd_cache [list][scan8[7 ]+1]);\n AV_ZERO32(h->mvd_cache [list][scan8[13]+1]);\n AV_ZERO32(h->mvd_cache [list][scan8[4 ]]);\n AV_ZERO32(h->mvd_cache [list][scan8[12]]);\n if(h->slice_type_nos == FF_B_TYPE){\n fill_rectangle(&h->direct_cache[scan8[0]], 4, 4, 8, MB_TYPE_16x16>>1, 1);\n if(IS_DIRECT(top_type)){\n AV_WN32A(&h->direct_cache[scan8[0] - 1*8], 0x01010101*(MB_TYPE_DIRECT2>>1));\n }else if(IS_8X8(top_type)){\n int b8_xy = h->mb2b8_xy[top_xy] + h->b8_stride;\n h->direct_cache[scan8[0] + 0 - 1*8]= h->direct_table[b8_xy];\n h->direct_cache[scan8[0] + 2 - 1*8]= h->direct_table[b8_xy + 1];\n }else{\n AV_WN32A(&h->direct_cache[scan8[0] - 1*8], 0x01010101*(MB_TYPE_16x16>>1));\n }\n if(IS_DIRECT(left_type[0]))\n h->direct_cache[scan8[0] - 1 + 0*8]= MB_TYPE_DIRECT2>>1;\n else if(IS_8X8(left_type[0]))\n h->direct_cache[scan8[0] - 1 + 0*8]= h->direct_table[h->mb2b8_xy[left_xy[0]] + 1 + h->b8_stride*(left_block[0]>>1)];\n else\n h->direct_cache[scan8[0] - 1 + 0*8]= MB_TYPE_16x16>>1;\n if(IS_DIRECT(left_type[1]))\n h->direct_cache[scan8[0] - 1 + 2*8]= MB_TYPE_DIRECT2>>1;\n else if(IS_8X8(left_type[1]))\n h->direct_cache[scan8[0] - 1 + 2*8]= h->direct_table[h->mb2b8_xy[left_xy[1]] + 1 + h->b8_stride*(left_block[2]>>1)];\n else\n h->direct_cache[scan8[0] - 1 + 2*8]= MB_TYPE_16x16>>1;\n }\n }\n }\n if(FRAME_MBAFF){\n#define MAP_MVS\\\n MAP_F2F(scan8[0] - 1 - 1*8, topleft_type)\\\n MAP_F2F(scan8[0] + 0 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 1 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 2 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 3 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 4 - 1*8, topright_type)\\\n MAP_F2F(scan8[0] - 1 + 0*8, left_type[0])\\\n MAP_F2F(scan8[0] - 1 + 1*8, left_type[0])\\\n MAP_F2F(scan8[0] - 1 + 2*8, left_type[1])\\\n MAP_F2F(scan8[0] - 1 + 3*8, left_type[1])\n if(MB_FIELD){\n#define MAP_F2F(idx, mb_type)\\\n if(!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\\\n h->ref_cache[list][idx] <<= 1;\\\n h->mv_cache[list][idx][1] /= 2;\\\n h->mvd_cache[list][idx][1] /= 2;\\\n }\n MAP_MVS\n#undef MAP_F2F\n }else{\n#define MAP_F2F(idx, mb_type)\\\n if(IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\\\n h->ref_cache[list][idx] >>= 1;\\\n h->mv_cache[list][idx][1] <<= 1;\\\n h->mvd_cache[list][idx][1] <<= 1;\\\n }\n MAP_MVS\n#undef MAP_F2F\n }\n }\n }\n }\n#endif\n h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[0]);\n}']
34,857
0
https://github.com/openssl/openssl/blob/9d46752dfecf26ccd62de33811eb30a19ffb87ac/test/handshake_helper.c/#L821
static HANDSHAKE_RESULT *do_handshake_internal( SSL_CTX *server_ctx, SSL_CTX *server2_ctx, SSL_CTX *client_ctx, const SSL_TEST_EXTRA_CONF *extra, int app_data_size, SSL_SESSION *session_in, SSL_SESSION **session_out) { PEER server, client; BIO *client_to_server, *server_to_client; HANDSHAKE_EX_DATA server_ex_data, client_ex_data; CTX_DATA client_ctx_data, server_ctx_data, server2_ctx_data; HANDSHAKE_RESULT *ret = HANDSHAKE_RESULT_new(); int client_turn = 1; connect_phase_t phase = HANDSHAKE; handshake_status_t status = HANDSHAKE_RETRY; unsigned char* tick = NULL; size_t tick_len = 0; SSL_SESSION* sess = NULL; const unsigned char *proto = NULL; unsigned int proto_len = 0; memset(&server_ctx_data, 0, sizeof(server_ctx_data)); memset(&server2_ctx_data, 0, sizeof(server2_ctx_data)); memset(&client_ctx_data, 0, sizeof(client_ctx_data)); memset(&server, 0, sizeof(server)); memset(&client, 0, sizeof(client)); configure_handshake_ctx(server_ctx, server2_ctx, client_ctx, extra, &server_ctx_data, &server2_ctx_data, &client_ctx_data); create_peer(&server, server_ctx); create_peer(&client, client_ctx); server.bytes_to_write = client.bytes_to_read = app_data_size; client.bytes_to_write = server.bytes_to_read = app_data_size; configure_handshake_ssl(server.ssl, client.ssl, extra); if (session_in != NULL) { TEST_check(SSL_CTX_add_session(server_ctx, session_in)); TEST_check(SSL_set_session(client.ssl, session_in)); } memset(&server_ex_data, 0, sizeof(server_ex_data)); memset(&client_ex_data, 0, sizeof(client_ex_data)); ret->result = SSL_TEST_INTERNAL_ERROR; client_to_server = BIO_new(BIO_s_mem()); server_to_client = BIO_new(BIO_s_mem()); TEST_check(client_to_server != NULL); TEST_check(server_to_client != NULL); BIO_set_nbio(client_to_server, 1); BIO_set_nbio(server_to_client, 1); SSL_set_connect_state(client.ssl); SSL_set_accept_state(server.ssl); SSL_set_bio(client.ssl, server_to_client, client_to_server); TEST_check(BIO_up_ref(server_to_client) > 0); TEST_check(BIO_up_ref(client_to_server) > 0); SSL_set_bio(server.ssl, client_to_server, server_to_client); ex_data_idx = SSL_get_ex_new_index(0, "ex data", NULL, NULL, NULL); TEST_check(ex_data_idx >= 0); TEST_check(SSL_set_ex_data(server.ssl, ex_data_idx, &server_ex_data) == 1); TEST_check(SSL_set_ex_data(client.ssl, ex_data_idx, &client_ex_data) == 1); SSL_set_info_callback(server.ssl, &info_cb); SSL_set_info_callback(client.ssl, &info_cb); client.status = server.status = PEER_RETRY; for(;;) { if (client_turn) { do_connect_step(&client, phase); status = handshake_status(client.status, server.status, 1 ); } else { do_connect_step(&server, phase); status = handshake_status(server.status, client.status, 0 ); } switch (status) { case HANDSHAKE_SUCCESS: phase = next_phase(phase); if (phase == CONNECTION_DONE) { ret->result = SSL_TEST_SUCCESS; goto err; } else { client.status = server.status = PEER_RETRY; client_turn = 1; break; } case CLIENT_ERROR: ret->result = SSL_TEST_CLIENT_FAIL; goto err; case SERVER_ERROR: ret->result = SSL_TEST_SERVER_FAIL; goto err; case INTERNAL_ERROR: ret->result = SSL_TEST_INTERNAL_ERROR; goto err; case HANDSHAKE_RETRY: client_turn ^= 1; break; } } err: ret->server_alert_sent = server_ex_data.alert_sent; ret->server_alert_received = client_ex_data.alert_received; ret->client_alert_sent = client_ex_data.alert_sent; ret->client_alert_received = server_ex_data.alert_received; ret->server_protocol = SSL_version(server.ssl); ret->client_protocol = SSL_version(client.ssl); ret->servername = server_ex_data.servername; if ((sess = SSL_get0_session(client.ssl)) != NULL) SSL_SESSION_get0_ticket(sess, &tick, &tick_len); if (tick == NULL || tick_len == 0) ret->session_ticket = SSL_TEST_SESSION_TICKET_NO; else ret->session_ticket = SSL_TEST_SESSION_TICKET_YES; ret->session_ticket_do_not_call = server_ex_data.session_ticket_do_not_call; #ifndef OPENSSL_NO_NEXTPROTONEG SSL_get0_next_proto_negotiated(client.ssl, &proto, &proto_len); ret->client_npn_negotiated = dup_str(proto, proto_len); SSL_get0_next_proto_negotiated(server.ssl, &proto, &proto_len); ret->server_npn_negotiated = dup_str(proto, proto_len); #endif SSL_get0_alpn_selected(client.ssl, &proto, &proto_len); ret->client_alpn_negotiated = dup_str(proto, proto_len); SSL_get0_alpn_selected(server.ssl, &proto, &proto_len); ret->server_alpn_negotiated = dup_str(proto, proto_len); ret->client_resumed = SSL_session_reused(client.ssl); ret->server_resumed = SSL_session_reused(server.ssl); if (session_out != NULL) *session_out = SSL_get1_session(client.ssl); ctx_data_free_data(&server_ctx_data); ctx_data_free_data(&server2_ctx_data); ctx_data_free_data(&client_ctx_data); peer_free_data(&server); peer_free_data(&client); return ret; }
['static HANDSHAKE_RESULT *do_handshake_internal(\n SSL_CTX *server_ctx, SSL_CTX *server2_ctx, SSL_CTX *client_ctx,\n const SSL_TEST_EXTRA_CONF *extra, int app_data_size,\n SSL_SESSION *session_in, SSL_SESSION **session_out)\n{\n PEER server, client;\n BIO *client_to_server, *server_to_client;\n HANDSHAKE_EX_DATA server_ex_data, client_ex_data;\n CTX_DATA client_ctx_data, server_ctx_data, server2_ctx_data;\n HANDSHAKE_RESULT *ret = HANDSHAKE_RESULT_new();\n int client_turn = 1;\n connect_phase_t phase = HANDSHAKE;\n handshake_status_t status = HANDSHAKE_RETRY;\n unsigned char* tick = NULL;\n size_t tick_len = 0;\n SSL_SESSION* sess = NULL;\n const unsigned char *proto = NULL;\n unsigned int proto_len = 0;\n memset(&server_ctx_data, 0, sizeof(server_ctx_data));\n memset(&server2_ctx_data, 0, sizeof(server2_ctx_data));\n memset(&client_ctx_data, 0, sizeof(client_ctx_data));\n memset(&server, 0, sizeof(server));\n memset(&client, 0, sizeof(client));\n configure_handshake_ctx(server_ctx, server2_ctx, client_ctx, extra,\n &server_ctx_data, &server2_ctx_data, &client_ctx_data);\n create_peer(&server, server_ctx);\n create_peer(&client, client_ctx);\n server.bytes_to_write = client.bytes_to_read = app_data_size;\n client.bytes_to_write = server.bytes_to_read = app_data_size;\n configure_handshake_ssl(server.ssl, client.ssl, extra);\n if (session_in != NULL) {\n TEST_check(SSL_CTX_add_session(server_ctx, session_in));\n TEST_check(SSL_set_session(client.ssl, session_in));\n }\n memset(&server_ex_data, 0, sizeof(server_ex_data));\n memset(&client_ex_data, 0, sizeof(client_ex_data));\n ret->result = SSL_TEST_INTERNAL_ERROR;\n client_to_server = BIO_new(BIO_s_mem());\n server_to_client = BIO_new(BIO_s_mem());\n TEST_check(client_to_server != NULL);\n TEST_check(server_to_client != NULL);\n BIO_set_nbio(client_to_server, 1);\n BIO_set_nbio(server_to_client, 1);\n SSL_set_connect_state(client.ssl);\n SSL_set_accept_state(server.ssl);\n SSL_set_bio(client.ssl, server_to_client, client_to_server);\n TEST_check(BIO_up_ref(server_to_client) > 0);\n TEST_check(BIO_up_ref(client_to_server) > 0);\n SSL_set_bio(server.ssl, client_to_server, server_to_client);\n ex_data_idx = SSL_get_ex_new_index(0, "ex data", NULL, NULL, NULL);\n TEST_check(ex_data_idx >= 0);\n TEST_check(SSL_set_ex_data(server.ssl, ex_data_idx, &server_ex_data) == 1);\n TEST_check(SSL_set_ex_data(client.ssl, ex_data_idx, &client_ex_data) == 1);\n SSL_set_info_callback(server.ssl, &info_cb);\n SSL_set_info_callback(client.ssl, &info_cb);\n client.status = server.status = PEER_RETRY;\n for(;;) {\n if (client_turn) {\n do_connect_step(&client, phase);\n status = handshake_status(client.status, server.status,\n 1 );\n } else {\n do_connect_step(&server, phase);\n status = handshake_status(server.status, client.status,\n 0 );\n }\n switch (status) {\n case HANDSHAKE_SUCCESS:\n phase = next_phase(phase);\n if (phase == CONNECTION_DONE) {\n ret->result = SSL_TEST_SUCCESS;\n goto err;\n } else {\n client.status = server.status = PEER_RETRY;\n client_turn = 1;\n break;\n }\n case CLIENT_ERROR:\n ret->result = SSL_TEST_CLIENT_FAIL;\n goto err;\n case SERVER_ERROR:\n ret->result = SSL_TEST_SERVER_FAIL;\n goto err;\n case INTERNAL_ERROR:\n ret->result = SSL_TEST_INTERNAL_ERROR;\n goto err;\n case HANDSHAKE_RETRY:\n client_turn ^= 1;\n break;\n }\n }\n err:\n ret->server_alert_sent = server_ex_data.alert_sent;\n ret->server_alert_received = client_ex_data.alert_received;\n ret->client_alert_sent = client_ex_data.alert_sent;\n ret->client_alert_received = server_ex_data.alert_received;\n ret->server_protocol = SSL_version(server.ssl);\n ret->client_protocol = SSL_version(client.ssl);\n ret->servername = server_ex_data.servername;\n if ((sess = SSL_get0_session(client.ssl)) != NULL)\n SSL_SESSION_get0_ticket(sess, &tick, &tick_len);\n if (tick == NULL || tick_len == 0)\n ret->session_ticket = SSL_TEST_SESSION_TICKET_NO;\n else\n ret->session_ticket = SSL_TEST_SESSION_TICKET_YES;\n ret->session_ticket_do_not_call = server_ex_data.session_ticket_do_not_call;\n#ifndef OPENSSL_NO_NEXTPROTONEG\n SSL_get0_next_proto_negotiated(client.ssl, &proto, &proto_len);\n ret->client_npn_negotiated = dup_str(proto, proto_len);\n SSL_get0_next_proto_negotiated(server.ssl, &proto, &proto_len);\n ret->server_npn_negotiated = dup_str(proto, proto_len);\n#endif\n SSL_get0_alpn_selected(client.ssl, &proto, &proto_len);\n ret->client_alpn_negotiated = dup_str(proto, proto_len);\n SSL_get0_alpn_selected(server.ssl, &proto, &proto_len);\n ret->server_alpn_negotiated = dup_str(proto, proto_len);\n ret->client_resumed = SSL_session_reused(client.ssl);\n ret->server_resumed = SSL_session_reused(server.ssl);\n if (session_out != NULL)\n *session_out = SSL_get1_session(client.ssl);\n ctx_data_free_data(&server_ctx_data);\n ctx_data_free_data(&server2_ctx_data);\n ctx_data_free_data(&client_ctx_data);\n peer_free_data(&server);\n peer_free_data(&client);\n return ret;\n}']
34,858
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_ctx.c/#L328
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['static int rsa_ossl_private_encrypt(int flen, const unsigned char *from,\n unsigned char *to, RSA *rsa, int padding)\n{\n BIGNUM *f, *ret, *res;\n int i, j, k, num = 0, r = -1;\n unsigned char *buf = NULL;\n BN_CTX *ctx = NULL;\n int local_blinding = 0;\n BIGNUM *unblind = NULL;\n BN_BLINDING *blinding = NULL;\n if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n BN_CTX_start(ctx);\n f = BN_CTX_get(ctx);\n ret = BN_CTX_get(ctx);\n num = BN_num_bytes(rsa->n);\n buf = OPENSSL_malloc(num);\n if (f == NULL || ret == NULL || buf == NULL) {\n RSAerr(RSA_F_RSA_OSSL_PRIVATE_ENCRYPT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n switch (padding) {\n case RSA_PKCS1_PADDING:\n i = RSA_padding_add_PKCS1_type_1(buf, num, from, flen);\n break;\n case RSA_X931_PADDING:\n i = RSA_padding_add_X931(buf, num, from, flen);\n break;\n case RSA_NO_PADDING:\n i = RSA_padding_add_none(buf, num, from, flen);\n break;\n case RSA_SSLV23_PADDING:\n default:\n RSAerr(RSA_F_RSA_OSSL_PRIVATE_ENCRYPT, RSA_R_UNKNOWN_PADDING_TYPE);\n goto err;\n }\n if (i <= 0)\n goto err;\n if (BN_bin2bn(buf, num, f) == NULL)\n goto err;\n if (BN_ucmp(f, rsa->n) >= 0) {\n RSAerr(RSA_F_RSA_OSSL_PRIVATE_ENCRYPT,\n RSA_R_DATA_TOO_LARGE_FOR_MODULUS);\n goto err;\n }\n if (!(rsa->flags & RSA_FLAG_NO_BLINDING)) {\n blinding = rsa_get_blinding(rsa, &local_blinding, ctx);\n if (blinding == NULL) {\n RSAerr(RSA_F_RSA_OSSL_PRIVATE_ENCRYPT, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n }\n if (blinding != NULL) {\n if (!local_blinding && ((unblind = BN_CTX_get(ctx)) == NULL)) {\n RSAerr(RSA_F_RSA_OSSL_PRIVATE_ENCRYPT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (!rsa_blinding_convert(blinding, f, unblind, ctx))\n goto err;\n }\n if ((rsa->flags & RSA_FLAG_EXT_PKEY) ||\n ((rsa->p != NULL) &&\n (rsa->q != NULL) &&\n (rsa->dmp1 != NULL) && (rsa->dmq1 != NULL) && (rsa->iqmp != NULL))) {\n if (!rsa->meth->rsa_mod_exp(ret, f, rsa, ctx))\n goto err;\n } else {\n BIGNUM *d = NULL, *local_d = NULL;\n if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) {\n local_d = d = BN_new();\n if (d == NULL) {\n RSAerr(RSA_F_RSA_OSSL_PRIVATE_ENCRYPT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);\n } else {\n d = rsa->d;\n }\n if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)\n if (!BN_MONT_CTX_set_locked\n (&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx)) {\n BN_free(local_d);\n goto err;\n }\n if (!rsa->meth->bn_mod_exp(ret, f, d, rsa->n, ctx,\n rsa->_method_mod_n)) {\n BN_free(local_d);\n goto err;\n }\n BN_free(local_d);\n }\n if (blinding)\n if (!rsa_blinding_invert(blinding, ret, unblind, ctx))\n goto err;\n if (padding == RSA_X931_PADDING) {\n BN_sub(f, rsa->n, ret);\n if (BN_cmp(ret, f) > 0)\n res = f;\n else\n res = ret;\n } else\n res = ret;\n j = BN_num_bytes(res);\n i = BN_bn2bin(res, &(to[num - j]));\n for (k = 0; k < (num - i); k++)\n to[k] = 0;\n r = num;\n err:\n if (ctx != NULL)\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n OPENSSL_clear_free(buf, num);\n return (r);\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'static int rsa_blinding_invert(BN_BLINDING *b, BIGNUM *f, BIGNUM *unblind,\n BN_CTX *ctx)\n{\n return BN_BLINDING_invert_ex(f, unblind, b, ctx);\n}', 'int BN_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(n);\n if (r != NULL)\n ret = BN_mod_mul(n, n, r, b->mod, ctx);\n else {\n if (b->Ai == NULL) {\n BNerr(BN_F_BN_BLINDING_INVERT_EX, BN_R_NOT_INITIALIZED);\n return (0);\n }\n ret = BN_mod_mul(n, n, b->Ai, b->mod, ctx);\n }\n bn_check_top(n);\n return (ret);\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return (ret);\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (!rr || !tmp)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n if (a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))\n rr->top = max - 1;\n else\n rr->top = max;\n if (rr != r)\n BN_copy(r, rr);\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return (ret);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
34,859
0
https://github.com/libav/libav/blob/cf6bae6883607f83f3b042b7b9d711197f736e2a/libswscale/swscale.c/#L3279
SwsVector *sws_cloneVec(SwsVector *a){ double *coeff= av_malloc(a->length*sizeof(double)); int i; SwsVector *vec= av_malloc(sizeof(SwsVector)); vec->coeff= coeff; vec->length= a->length; for (i=0; i<a->length; i++) coeff[i]= a->coeff[i]; return vec; }
['SwsVector *sws_cloneVec(SwsVector *a){\n double *coeff= av_malloc(a->length*sizeof(double));\n int i;\n SwsVector *vec= av_malloc(sizeof(SwsVector));\n vec->coeff= coeff;\n vec->length= a->length;\n for (i=0; i<a->length; i++) coeff[i]= a->coeff[i];\n return vec;\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
34,860
0
https://github.com/nginx/nginx/blob/e4ecddfdb0d2ffc872658e36028971ad9a873726/src/core/ngx_string.c/#L244
u_char * ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args) { u_char *p, zero, *last; int d; float f, scale; size_t len, slen; int64_t i64; uint64_t ui64; ngx_msec_t ms; ngx_uint_t width, sign, hex, max_width, frac_width, i; ngx_str_t *v; ngx_variable_value_t *vv; if (max == 0) { return buf; } last = buf + max; while (*fmt && buf < last) { if (*fmt == '%') { i64 = 0; ui64 = 0; zero = (u_char) ((*++fmt == '0') ? '0' : ' '); width = 0; sign = 1; hex = 0; max_width = 0; frac_width = 0; slen = (size_t) -1; while (*fmt >= '0' && *fmt <= '9') { width = width * 10 + *fmt++ - '0'; } for ( ;; ) { switch (*fmt) { case 'u': sign = 0; fmt++; continue; case 'm': max_width = 1; fmt++; continue; case 'X': hex = 2; sign = 0; fmt++; continue; case 'x': hex = 1; sign = 0; fmt++; continue; case '.': fmt++; while (*fmt >= '0' && *fmt <= '9') { frac_width = frac_width * 10 + *fmt++ - '0'; } break; case '*': slen = va_arg(args, size_t); fmt++; continue; default: break; } break; } switch (*fmt) { case 'V': v = va_arg(args, ngx_str_t *); len = v->len; len = (buf + len < last) ? len : (size_t) (last - buf); buf = ngx_cpymem(buf, v->data, len); fmt++; continue; case 'v': vv = va_arg(args, ngx_variable_value_t *); len = vv->len; len = (buf + len < last) ? len : (size_t) (last - buf); buf = ngx_cpymem(buf, vv->data, len); fmt++; continue; case 's': p = va_arg(args, u_char *); if (slen == (size_t) -1) { while (*p && buf < last) { *buf++ = *p++; } } else { len = (buf + slen < last) ? slen : (size_t) (last - buf); buf = ngx_cpymem(buf, p, len); } fmt++; continue; case 'O': i64 = (int64_t) va_arg(args, off_t); sign = 1; break; case 'P': i64 = (int64_t) va_arg(args, ngx_pid_t); sign = 1; break; case 'T': i64 = (int64_t) va_arg(args, time_t); sign = 1; break; case 'M': ms = (ngx_msec_t) va_arg(args, ngx_msec_t); if ((ngx_msec_int_t) ms == -1) { sign = 1; i64 = -1; } else { sign = 0; ui64 = (uint64_t) ms; } break; case 'z': if (sign) { i64 = (int64_t) va_arg(args, ssize_t); } else { ui64 = (uint64_t) va_arg(args, size_t); } break; case 'i': if (sign) { i64 = (int64_t) va_arg(args, ngx_int_t); } else { ui64 = (uint64_t) va_arg(args, ngx_uint_t); } if (max_width) { width = NGX_INT_T_LEN; } break; case 'd': if (sign) { i64 = (int64_t) va_arg(args, int); } else { ui64 = (uint64_t) va_arg(args, u_int); } break; case 'l': if (sign) { i64 = (int64_t) va_arg(args, long); } else { ui64 = (uint64_t) va_arg(args, u_long); } break; case 'D': if (sign) { i64 = (int64_t) va_arg(args, int32_t); } else { ui64 = (uint64_t) va_arg(args, uint32_t); } break; case 'L': if (sign) { i64 = va_arg(args, int64_t); } else { ui64 = va_arg(args, uint64_t); } break; case 'A': if (sign) { i64 = (int64_t) va_arg(args, ngx_atomic_int_t); } else { ui64 = (uint64_t) va_arg(args, ngx_atomic_uint_t); } if (max_width) { width = NGX_ATOMIC_T_LEN; } break; case 'f': f = (float) va_arg(args, double); if (f < 0) { *buf++ = '-'; f = -f; } ui64 = (int64_t) f; buf = ngx_sprintf_num(buf, last, ui64, zero, 0, width); if (frac_width) { if (buf < last) { *buf++ = '.'; } scale = 1.0; for (i = 0; i < frac_width; i++) { scale *= 10.0; } ui64 = (uint64_t) ((f - (int64_t) ui64) * scale); buf = ngx_sprintf_num(buf, last, ui64, '0', 0, frac_width); } fmt++; continue; #if !(NGX_WIN32) case 'r': i64 = (int64_t) va_arg(args, rlim_t); sign = 1; break; #endif case 'p': ui64 = (uintptr_t) va_arg(args, void *); hex = 2; sign = 0; zero = '0'; width = NGX_PTR_SIZE * 2; break; case 'c': d = va_arg(args, int); *buf++ = (u_char) (d & 0xff); fmt++; continue; case 'Z': *buf++ = '\0'; fmt++; continue; case 'N': #if (NGX_WIN32) *buf++ = CR; #endif *buf++ = LF; fmt++; continue; case '%': *buf++ = '%'; fmt++; continue; default: *buf++ = *fmt++; continue; } if (sign) { if (i64 < 0) { *buf++ = '-'; ui64 = (uint64_t) -i64; } else { ui64 = (uint64_t) i64; } } buf = ngx_sprintf_num(buf, last, ui64, zero, hex, width); fmt++; } else { *buf++ = *fmt++; } } return buf; }
['void\nngx_event_accept(ngx_event_t *ev)\n{\n socklen_t socklen;\n ngx_err_t err;\n ngx_log_t *log;\n ngx_socket_t s;\n ngx_event_t *rev, *wev;\n ngx_listening_t *ls;\n ngx_connection_t *c, *lc;\n ngx_event_conf_t *ecf;\n u_char sa[NGX_SOCKADDRLEN];\n ecf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_event_core_module);\n if (ngx_event_flags & NGX_USE_RTSIG_EVENT) {\n ev->available = 1;\n } else if (!(ngx_event_flags & NGX_USE_KQUEUE_EVENT)) {\n ev->available = ecf->multi_accept;\n }\n lc = ev->data;\n ls = lc->listening;\n ev->ready = 0;\n ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,\n "accept on %V, ready: %d", &ls->addr_text, ev->available);\n do {\n socklen = NGX_SOCKADDRLEN;\n s = accept(lc->fd, (struct sockaddr *) sa, &socklen);\n if (s == -1) {\n err = ngx_socket_errno;\n if (err == NGX_EAGAIN) {\n ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, err,\n "accept() not ready");\n return;\n }\n ngx_log_error((err == NGX_ECONNABORTED) ? NGX_LOG_ERR:\n NGX_LOG_ALERT,\n ev->log, err, "accept() failed");\n if (err == NGX_ECONNABORTED) {\n if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {\n ev->available--;\n }\n if (ev->available) {\n continue;\n }\n }\n return;\n }\n#if (NGX_STAT_STUB)\n ngx_atomic_fetch_add(ngx_stat_accepted, 1);\n#endif\n ngx_accept_disabled = ngx_cycle->connection_n / 8\n - ngx_cycle->free_connection_n;\n c = ngx_get_connection(s, ev->log);\n if (c == NULL) {\n if (ngx_close_socket(s) == -1) {\n ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno,\n ngx_close_socket_n " failed");\n }\n return;\n }\n#if (NGX_STAT_STUB)\n ngx_atomic_fetch_add(ngx_stat_active, 1);\n#endif\n c->pool = ngx_create_pool(ls->pool_size, ev->log);\n if (c->pool == NULL) {\n ngx_close_accepted_connection(c);\n return;\n }\n c->sockaddr = ngx_palloc(c->pool, socklen);\n if (c->sockaddr == NULL) {\n ngx_close_accepted_connection(c);\n return;\n }\n ngx_memcpy(c->sockaddr, sa, socklen);\n log = ngx_palloc(c->pool, sizeof(ngx_log_t));\n if (log == NULL) {\n ngx_close_accepted_connection(c);\n return;\n }\n if (ngx_inherited_nonblocking) {\n if (ngx_event_flags & NGX_USE_AIO_EVENT) {\n if (ngx_blocking(s) == -1) {\n ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno,\n ngx_blocking_n " failed");\n ngx_close_accepted_connection(c);\n return;\n }\n }\n } else {\n if (!(ngx_event_flags & (NGX_USE_AIO_EVENT|NGX_USE_RTSIG_EVENT))) {\n if (ngx_nonblocking(s) == -1) {\n ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno,\n ngx_nonblocking_n " failed");\n ngx_close_accepted_connection(c);\n return;\n }\n }\n }\n *log = ls->log;\n c->recv = ngx_recv;\n c->send = ngx_send;\n c->recv_chain = ngx_recv_chain;\n c->send_chain = ngx_send_chain;\n c->log = log;\n c->pool->log = log;\n c->socklen = socklen;\n c->listening = ls;\n c->local_sockaddr = ls->sockaddr;\n c->local_socklen = ls->socklen;\n c->unexpected_eof = 1;\n rev = c->read;\n wev = c->write;\n wev->ready = 1;\n if (ngx_event_flags & (NGX_USE_AIO_EVENT|NGX_USE_RTSIG_EVENT)) {\n rev->ready = 1;\n }\n if (ev->deferred_accept) {\n rev->ready = 1;\n#if (NGX_HAVE_KQUEUE)\n rev->available = 1;\n#endif\n }\n rev->log = log;\n wev->log = log;\n c->number = ngx_atomic_fetch_add(ngx_connection_counter, 1);\n#if (NGX_STAT_STUB)\n ngx_atomic_fetch_add(ngx_stat_handled, 1);\n#endif\n#if (NGX_THREADS)\n rev->lock = &c->lock;\n wev->lock = &c->lock;\n rev->own_lock = &c->lock;\n wev->own_lock = &c->lock;\n#endif\n if (ls->addr_ntop) {\n c->addr_text.data = ngx_pnalloc(c->pool, ls->addr_text_max_len);\n if (c->addr_text.data == NULL) {\n ngx_close_accepted_connection(c);\n return;\n }\n c->addr_text.len = ngx_sock_ntop(c->sockaddr, c->addr_text.data,\n ls->addr_text_max_len, 0);\n if (c->addr_text.len == 0) {\n ngx_close_accepted_connection(c);\n return;\n }\n }\n#if (NGX_DEBUG)\n {\n in_addr_t i;\n ngx_event_debug_t *dc;\n struct sockaddr_in *sin;\n sin = (struct sockaddr_in *) sa;\n dc = ecf->debug_connection.elts;\n for (i = 0; i < ecf->debug_connection.nelts; i++) {\n if ((sin->sin_addr.s_addr & dc[i].mask) == dc[i].addr) {\n log->log_level = NGX_LOG_DEBUG_CONNECTION|NGX_LOG_DEBUG_ALL;\n break;\n }\n }\n }\n#endif\n ngx_log_debug3(NGX_LOG_DEBUG_EVENT, log, 0,\n "*%d accept: %V fd:%d", c->number, &c->addr_text, s);\n if (ngx_add_conn && (ngx_event_flags & NGX_USE_EPOLL_EVENT) == 0) {\n if (ngx_add_conn(c) == NGX_ERROR) {\n ngx_close_accepted_connection(c);\n return;\n }\n }\n log->data = NULL;\n log->handler = NULL;\n ls->handler(c);\n if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {\n ev->available--;\n }\n } while (ev->available);\n}', 'void\nngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,\n const char *fmt, ...)\n#else\nvoid\nngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,\n const char *fmt, va_list args)\n#endif\n{\n#if (NGX_HAVE_VARIADIC_MACROS)\n va_list args;\n#endif\n u_char errstr[NGX_MAX_ERROR_STR], *p, *last;\n if (log->file->fd == NGX_INVALID_FILE) {\n return;\n }\n last = errstr + NGX_MAX_ERROR_STR;\n ngx_memcpy(errstr, ngx_cached_err_log_time.data,\n ngx_cached_err_log_time.len);\n p = errstr + ngx_cached_err_log_time.len;\n p = ngx_snprintf(p, last - p, " [%s] ", err_levels[level]);\n p = ngx_snprintf(p, last - p, "%P#" NGX_TID_T_FMT ": ",\n ngx_log_pid, ngx_log_tid);\n if (log->connection) {\n p = ngx_snprintf(p, last - p, "*%uA ", log->connection);\n }\n#if (NGX_HAVE_VARIADIC_MACROS)\n va_start(args, fmt);\n p = ngx_vsnprintf(p, last - p, fmt, args);\n va_end(args);\n#else\n p = ngx_vsnprintf(p, last - p, fmt, args);\n#endif\n if (err) {\n if (p > last - 50) {\n p = last - 50;\n *p++ = \'.\';\n *p++ = \'.\';\n *p++ = \'.\';\n }\n#if (NGX_WIN32)\n p = ngx_snprintf(p, last - p, ((unsigned) err < 0x80000000)\n ? " (%d: " : " (%Xd: ", err);\n#else\n p = ngx_snprintf(p, last - p, " (%d: ", err);\n#endif\n p = ngx_strerror_r(err, p, last - p);\n if (p < last) {\n *p++ = \')\';\n }\n }\n if (level != NGX_LOG_DEBUG && log->handler) {\n p = log->handler(log, p, last - p);\n }\n if (p > last - NGX_LINEFEED_SIZE) {\n p = last - NGX_LINEFEED_SIZE;\n }\n ngx_linefeed(p);\n (void) ngx_write_fd(log->file->fd, errstr, p - errstr);\n}', 'u_char * ngx_cdecl\nngx_snprintf(u_char *buf, size_t max, const char *fmt, ...)\n{\n u_char *p;\n va_list args;\n va_start(args, fmt);\n p = ngx_vsnprintf(buf, max, fmt, args);\n va_end(args);\n return p;\n}', "u_char *\nngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args)\n{\n u_char *p, zero, *last;\n int d;\n float f, scale;\n size_t len, slen;\n int64_t i64;\n uint64_t ui64;\n ngx_msec_t ms;\n ngx_uint_t width, sign, hex, max_width, frac_width, i;\n ngx_str_t *v;\n ngx_variable_value_t *vv;\n if (max == 0) {\n return buf;\n }\n last = buf + max;\n while (*fmt && buf < last) {\n if (*fmt == '%') {\n i64 = 0;\n ui64 = 0;\n zero = (u_char) ((*++fmt == '0') ? '0' : ' ');\n width = 0;\n sign = 1;\n hex = 0;\n max_width = 0;\n frac_width = 0;\n slen = (size_t) -1;\n while (*fmt >= '0' && *fmt <= '9') {\n width = width * 10 + *fmt++ - '0';\n }\n for ( ;; ) {\n switch (*fmt) {\n case 'u':\n sign = 0;\n fmt++;\n continue;\n case 'm':\n max_width = 1;\n fmt++;\n continue;\n case 'X':\n hex = 2;\n sign = 0;\n fmt++;\n continue;\n case 'x':\n hex = 1;\n sign = 0;\n fmt++;\n continue;\n case '.':\n fmt++;\n while (*fmt >= '0' && *fmt <= '9') {\n frac_width = frac_width * 10 + *fmt++ - '0';\n }\n break;\n case '*':\n slen = va_arg(args, size_t);\n fmt++;\n continue;\n default:\n break;\n }\n break;\n }\n switch (*fmt) {\n case 'V':\n v = va_arg(args, ngx_str_t *);\n len = v->len;\n len = (buf + len < last) ? len : (size_t) (last - buf);\n buf = ngx_cpymem(buf, v->data, len);\n fmt++;\n continue;\n case 'v':\n vv = va_arg(args, ngx_variable_value_t *);\n len = vv->len;\n len = (buf + len < last) ? len : (size_t) (last - buf);\n buf = ngx_cpymem(buf, vv->data, len);\n fmt++;\n continue;\n case 's':\n p = va_arg(args, u_char *);\n if (slen == (size_t) -1) {\n while (*p && buf < last) {\n *buf++ = *p++;\n }\n } else {\n len = (buf + slen < last) ? slen : (size_t) (last - buf);\n buf = ngx_cpymem(buf, p, len);\n }\n fmt++;\n continue;\n case 'O':\n i64 = (int64_t) va_arg(args, off_t);\n sign = 1;\n break;\n case 'P':\n i64 = (int64_t) va_arg(args, ngx_pid_t);\n sign = 1;\n break;\n case 'T':\n i64 = (int64_t) va_arg(args, time_t);\n sign = 1;\n break;\n case 'M':\n ms = (ngx_msec_t) va_arg(args, ngx_msec_t);\n if ((ngx_msec_int_t) ms == -1) {\n sign = 1;\n i64 = -1;\n } else {\n sign = 0;\n ui64 = (uint64_t) ms;\n }\n break;\n case 'z':\n if (sign) {\n i64 = (int64_t) va_arg(args, ssize_t);\n } else {\n ui64 = (uint64_t) va_arg(args, size_t);\n }\n break;\n case 'i':\n if (sign) {\n i64 = (int64_t) va_arg(args, ngx_int_t);\n } else {\n ui64 = (uint64_t) va_arg(args, ngx_uint_t);\n }\n if (max_width) {\n width = NGX_INT_T_LEN;\n }\n break;\n case 'd':\n if (sign) {\n i64 = (int64_t) va_arg(args, int);\n } else {\n ui64 = (uint64_t) va_arg(args, u_int);\n }\n break;\n case 'l':\n if (sign) {\n i64 = (int64_t) va_arg(args, long);\n } else {\n ui64 = (uint64_t) va_arg(args, u_long);\n }\n break;\n case 'D':\n if (sign) {\n i64 = (int64_t) va_arg(args, int32_t);\n } else {\n ui64 = (uint64_t) va_arg(args, uint32_t);\n }\n break;\n case 'L':\n if (sign) {\n i64 = va_arg(args, int64_t);\n } else {\n ui64 = va_arg(args, uint64_t);\n }\n break;\n case 'A':\n if (sign) {\n i64 = (int64_t) va_arg(args, ngx_atomic_int_t);\n } else {\n ui64 = (uint64_t) va_arg(args, ngx_atomic_uint_t);\n }\n if (max_width) {\n width = NGX_ATOMIC_T_LEN;\n }\n break;\n case 'f':\n f = (float) va_arg(args, double);\n if (f < 0) {\n *buf++ = '-';\n f = -f;\n }\n ui64 = (int64_t) f;\n buf = ngx_sprintf_num(buf, last, ui64, zero, 0, width);\n if (frac_width) {\n if (buf < last) {\n *buf++ = '.';\n }\n scale = 1.0;\n for (i = 0; i < frac_width; i++) {\n scale *= 10.0;\n }\n ui64 = (uint64_t) ((f - (int64_t) ui64) * scale);\n buf = ngx_sprintf_num(buf, last, ui64, '0', 0, frac_width);\n }\n fmt++;\n continue;\n#if !(NGX_WIN32)\n case 'r':\n i64 = (int64_t) va_arg(args, rlim_t);\n sign = 1;\n break;\n#endif\n case 'p':\n ui64 = (uintptr_t) va_arg(args, void *);\n hex = 2;\n sign = 0;\n zero = '0';\n width = NGX_PTR_SIZE * 2;\n break;\n case 'c':\n d = va_arg(args, int);\n *buf++ = (u_char) (d & 0xff);\n fmt++;\n continue;\n case 'Z':\n *buf++ = '\\0';\n fmt++;\n continue;\n case 'N':\n#if (NGX_WIN32)\n *buf++ = CR;\n#endif\n *buf++ = LF;\n fmt++;\n continue;\n case '%':\n *buf++ = '%';\n fmt++;\n continue;\n default:\n *buf++ = *fmt++;\n continue;\n }\n if (sign) {\n if (i64 < 0) {\n *buf++ = '-';\n ui64 = (uint64_t) -i64;\n } else {\n ui64 = (uint64_t) i64;\n }\n }\n buf = ngx_sprintf_num(buf, last, ui64, zero, hex, width);\n fmt++;\n } else {\n *buf++ = *fmt++;\n }\n }\n return buf;\n}"]
34,861
0
https://github.com/openssl/openssl/blob/24a5f17b6a221c327d292d7236b24717d5e413a9/crypto/bn/bn_ctx.c/#L355
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int test_probable_prime_coprime(BIO *bp, BN_CTX *ctx)\n\t{\n\tint i, j, ret = 0;\n\tBIGNUM *r;\n\tBN_ULONG primes[5] = { 2, 3, 5, 7, 11 };\n\tr = BN_new();\n\tfor (i = 0; i < 1000; i++)\n\t\t{\n\t\tif (!bn_probable_prime_dh_coprime(r, 1024, ctx)) goto err;\n\t\tfor (j = 0; j < 5; j++)\n\t\t\t{\n\t\t\tif (BN_mod_word(r, primes[j]) == 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bp, "Number generated is not coprime to %ld:\\n", primes[j]);\n\t\t\t\tBN_print_fp(stdout, r);\n\t\t\t\tBIO_printf(bp, "\\n");\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tret = 1;\nerr:\n\tBN_clear_free(r);\n\treturn ret;\n\t}', 'int bn_probable_prime_dh_coprime(BIGNUM *rnd, int bits, BN_CTX *ctx)\n\t{\n\tint i;\n\tBIGNUM *offset_index;\n\tBIGNUM *offset_count;\n\tint ret = 0;\n\tOPENSSL_assert(bits > prime_multiplier_bits);\n\tBN_CTX_start(ctx);\n\tif ((offset_index = BN_CTX_get(ctx)) == NULL) goto err;\n\tif ((offset_count = BN_CTX_get(ctx)) == NULL) goto err;\n\tBN_add_word(offset_count, prime_offset_count);\nloop:\n\tif (!BN_rand(rnd, bits - prime_multiplier_bits, 0, 1)) goto err;\n\tif (BN_is_bit_set(rnd, bits)) goto loop;\n\tif (!BN_rand_range(offset_index, offset_count)) goto err;\n\tBN_mul_word(rnd, prime_multiplier);\n\tBN_add_word(rnd, prime_offsets[BN_get_word(offset_index)]);\n\tfor (i = first_prime_index; i < NUMPRIMES; i++)\n\t\t{\n\t\tif (BN_mod_word(rnd, (BN_ULONG)primes[i]) <= 1)\n\t\t\t{\n\t\t\tgoto loop;\n\t\t\t}\n\t\t}\n\tret = 1;\nerr:\n\tBN_CTX_end(ctx);\n\tbn_check_top(rnd);\n\treturn ret;\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}']
34,862
0
https://github.com/libav/libav/blob/97334f106cfbf9787808b922bfb3c2973712f47d/libavformat/movenc.c/#L2124
static void mov_create_chapter_track(AVFormatContext *s, int tracknum) { MOVMuxContext *mov = s->priv_data; MOVTrack *track = &mov->tracks[tracknum]; AVPacket pkt = { .stream_index = tracknum, .flags = AV_PKT_FLAG_KEY }; int i, len; track->mode = mov->mode; track->tag = MKTAG('t','e','x','t'); track->timescale = MOV_TIMESCALE; track->enc = avcodec_alloc_context3(NULL); track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE; for (i = 0; i < s->nb_chapters; i++) { AVChapter *c = s->chapters[i]; AVDictionaryEntry *t; int64_t end = av_rescale_q(c->end, c->time_base, (AVRational){1,MOV_TIMESCALE}); pkt.pts = pkt.dts = av_rescale_q(c->start, c->time_base, (AVRational){1,MOV_TIMESCALE}); pkt.duration = end - pkt.dts; if ((t = av_dict_get(c->metadata, "title", NULL, 0))) { len = strlen(t->value); pkt.size = len+2; pkt.data = av_malloc(pkt.size); AV_WB16(pkt.data, len); memcpy(pkt.data+2, t->value, len); ff_mov_write_packet(s, &pkt); av_freep(&pkt.data); } } }
['static void mov_create_chapter_track(AVFormatContext *s, int tracknum)\n{\n MOVMuxContext *mov = s->priv_data;\n MOVTrack *track = &mov->tracks[tracknum];\n AVPacket pkt = { .stream_index = tracknum, .flags = AV_PKT_FLAG_KEY };\n int i, len;\n track->mode = mov->mode;\n track->tag = MKTAG(\'t\',\'e\',\'x\',\'t\');\n track->timescale = MOV_TIMESCALE;\n track->enc = avcodec_alloc_context3(NULL);\n track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;\n for (i = 0; i < s->nb_chapters; i++) {\n AVChapter *c = s->chapters[i];\n AVDictionaryEntry *t;\n int64_t end = av_rescale_q(c->end, c->time_base, (AVRational){1,MOV_TIMESCALE});\n pkt.pts = pkt.dts = av_rescale_q(c->start, c->time_base, (AVRational){1,MOV_TIMESCALE});\n pkt.duration = end - pkt.dts;\n if ((t = av_dict_get(c->metadata, "title", NULL, 0))) {\n len = strlen(t->value);\n pkt.size = len+2;\n pkt.data = av_malloc(pkt.size);\n AV_WB16(pkt.data, len);\n memcpy(pkt.data+2, t->value, len);\n ff_mov_write_packet(s, &pkt);\n av_freep(&pkt.data);\n }\n }\n}', 'AVCodecContext *avcodec_alloc_context3(AVCodec *codec){\n AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));\n if(avctx==NULL) return NULL;\n if(avcodec_get_context_defaults3(avctx, codec) < 0){\n av_free(avctx);\n return NULL;\n }\n return avctx;\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-32) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+32);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&31) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,32,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(32,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}', 'int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){\n int64_t b= bq.num * (int64_t)cq.den;\n int64_t c= cq.num * (int64_t)bq.den;\n return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);\n}', 'static av_always_inline av_const uint16_t av_bswap16(uint16_t x)\n{\n x= (x>>8) | (x<<8);\n return x;\n}']
34,863
0
https://github.com/openssl/openssl/blob/d40a1b865fddc3d67f8c06ff1f1466fad331c8f7/crypto/bn/bn_lib.c/#L250
int BN_num_bits(const BIGNUM *a) { int i = a->top - 1; bn_check_top(a); if (BN_is_zero(a)) return 0; return ((i*BN_BITS2) + BN_num_bits_word(a->d[i])); }
['static void jpake_receive_step3b(JPAKE_CTX *ctx, BIO *bconn)\n\t{\n\tJPAKE_STEP3B s3b;\n\tint l;\n\tJPAKE_STEP3B_init(&s3b);\n\tl = BIO_read(bconn, s3b.hk, sizeof s3b.hk);\n\tassert(l == sizeof s3b.hk);\n\tif(!JPAKE_STEP3B_process(ctx, &s3b))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\texit(1);\n\t\t}\n\tJPAKE_STEP3B_release(&s3b);\n\t}', 'int JPAKE_STEP3B_process(JPAKE_CTX *ctx, const JPAKE_STEP3B *received)\n {\n unsigned char hk[SHA_DIGEST_LENGTH];\n quickhashbn(hk, ctx->key);\n if(memcmp(hk, received->hk, sizeof hk))\n\t{\n\tJPAKEerr(JPAKE_F_JPAKE_STEP3B_PROCESS, JPAKE_R_HASH_OF_KEY_MISMATCH);\n\treturn 0;\n\t}\n return 1;\n }', 'static void quickhashbn(unsigned char *md, const BIGNUM *bn)\n {\n SHA_CTX sha;\n SHA1_Init(&sha);\n hashbn(&sha, bn);\n SHA1_Final(md, &sha);\n }', 'static void hashbn(SHA_CTX *sha, const BIGNUM *bn)\n {\n size_t l = BN_num_bytes(bn);\n unsigned char *bin = OPENSSL_malloc(l);\n hashlength(sha, l);\n BN_bn2bin(bn, bin);\n SHA1_Update(sha, bin, l);\n OPENSSL_free(bin);\n }', 'int BN_num_bits(const BIGNUM *a)\n\t{\n\tint i = a->top - 1;\n\tbn_check_top(a);\n\tif (BN_is_zero(a)) return 0;\n\treturn ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));\n\t}']
34,864
1
https://github.com/openssl/openssl/blob/3aecef76973dbea037ec4e1ceba7ec1bd3fb683a/crypto/objects/obj_dat.c/#L479
int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) { int i,idx=0,n=0,len,nid; unsigned long l; unsigned char *p; const char *s; char tbuf[32]; if (buf_len <= 0) return(0); if ((a == NULL) || (a->data == NULL)) { buf[0]='\0'; return(0); } if (no_name || (nid=OBJ_obj2nid(a)) == NID_undef) { len=a->length; p=a->data; idx=0; l=0; while (idx < a->length) { l|=(p[idx]&0x7f); if (!(p[idx] & 0x80)) break; l<<=7L; idx++; } idx++; i=(int)(l/40); if (i > 2) i=2; l-=(long)(i*40); sprintf(tbuf,"%d.%lu",i,l); i=strlen(tbuf); strncpy(buf,tbuf,buf_len); buf_len-=i; buf+=i; n+=i; l=0; for (; idx<len; idx++) { l|=p[idx]&0x7f; if (!(p[idx] & 0x80)) { sprintf(tbuf,".%lu",l); i=strlen(tbuf); if (buf_len > 0) strncpy(buf,tbuf,buf_len); buf_len-=i; buf+=i; n+=i; l=0; } l<<=7L; } } else { s=OBJ_nid2ln(nid); if (s == NULL) s=OBJ_nid2sn(nid); strncpy(buf,s,buf_len); n=strlen(s); } buf[buf_len-1]='\0'; return(n); }
['STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method,\n\t\t\t\tGENERAL_NAME *gen, STACK_OF(CONF_VALUE) *ret)\n{\n\tunsigned char *p;\n\tchar oline[256];\n\tswitch (gen->type)\n\t{\n\t\tcase GEN_OTHERNAME:\n\t\tX509V3_add_value("othername","<unsupported>", &ret);\n\t\tbreak;\n\t\tcase GEN_X400:\n\t\tX509V3_add_value("X400Name","<unsupported>", &ret);\n\t\tbreak;\n\t\tcase GEN_EDIPARTY:\n\t\tX509V3_add_value("EdiPartyName","<unsupported>", &ret);\n\t\tbreak;\n\t\tcase GEN_EMAIL:\n\t\tX509V3_add_value_uchar("email",gen->d.ia5->data, &ret);\n\t\tbreak;\n\t\tcase GEN_DNS:\n\t\tX509V3_add_value_uchar("DNS",gen->d.ia5->data, &ret);\n\t\tbreak;\n\t\tcase GEN_URI:\n\t\tX509V3_add_value_uchar("URI",gen->d.ia5->data, &ret);\n\t\tbreak;\n\t\tcase GEN_DIRNAME:\n\t\tX509_NAME_oneline(gen->d.dirn, oline, 256);\n\t\tX509V3_add_value("DirName",oline, &ret);\n\t\tbreak;\n\t\tcase GEN_IPADD:\n\t\tp = gen->d.ip->data;\n\t\tif(gen->d.ip->length != 4) {\n\t\t\tX509V3_add_value("IP Address","<invalid>", &ret);\n\t\t\tbreak;\n\t\t}\n\t\tsprintf(oline, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);\n\t\tX509V3_add_value("IP Address",oline, &ret);\n\t\tbreak;\n\t\tcase GEN_RID:\n\t\ti2t_ASN1_OBJECT(oline, 256, gen->d.rid);\n\t\tX509V3_add_value("Registered ID",oline, &ret);\n\t\tbreak;\n\t}\n\treturn ret;\n}', 'int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a)\n{\n\treturn OBJ_obj2txt(buf, buf_len, a, 0);\n}', 'int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)\n{\n\tint i,idx=0,n=0,len,nid;\n\tunsigned long l;\n\tunsigned char *p;\n\tconst char *s;\n\tchar tbuf[32];\n\tif (buf_len <= 0) return(0);\n\tif ((a == NULL) || (a->data == NULL)) {\n\t\tbuf[0]=\'\\0\';\n\t\treturn(0);\n\t}\n\tif (no_name || (nid=OBJ_obj2nid(a)) == NID_undef) {\n\t\tlen=a->length;\n\t\tp=a->data;\n\t\tidx=0;\n\t\tl=0;\n\t\twhile (idx < a->length) {\n\t\t\tl|=(p[idx]&0x7f);\n\t\t\tif (!(p[idx] & 0x80)) break;\n\t\t\tl<<=7L;\n\t\t\tidx++;\n\t\t}\n\t\tidx++;\n\t\ti=(int)(l/40);\n\t\tif (i > 2) i=2;\n\t\tl-=(long)(i*40);\n\t\tsprintf(tbuf,"%d.%lu",i,l);\n\t\ti=strlen(tbuf);\n\t\tstrncpy(buf,tbuf,buf_len);\n\t\tbuf_len-=i;\n\t\tbuf+=i;\n\t\tn+=i;\n\t\tl=0;\n\t\tfor (; idx<len; idx++) {\n\t\t\tl|=p[idx]&0x7f;\n\t\t\tif (!(p[idx] & 0x80)) {\n\t\t\t\tsprintf(tbuf,".%lu",l);\n\t\t\t\ti=strlen(tbuf);\n\t\t\t\tif (buf_len > 0)\n\t\t\t\t\tstrncpy(buf,tbuf,buf_len);\n\t\t\t\tbuf_len-=i;\n\t\t\t\tbuf+=i;\n\t\t\t\tn+=i;\n\t\t\t\tl=0;\n\t\t\t}\n\t\t\tl<<=7L;\n\t\t}\n\t} else {\n\t\ts=OBJ_nid2ln(nid);\n\t\tif (s == NULL)\n\t\t\ts=OBJ_nid2sn(nid);\n\t\tstrncpy(buf,s,buf_len);\n\t\tn=strlen(s);\n\t}\n\tbuf[buf_len-1]=\'\\0\';\n\treturn(n);\n}']
34,865
0
https://github.com/openssl/openssl/blob/9f9442918aeaed5dc2442d81ab8d29fe3e1fb906/crypto/bn/bn_lib.c/#L333
BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b) { bn_check_top(b); if (a == b) return a; if (bn_wexpand(a, b->top) == NULL) return NULL; if (b->top > 0) memcpy(a->d, b->d, sizeof(b->d[0]) * b->top); if (BN_get_flags(b, BN_FLG_CONSTTIME) != 0) BN_set_flags(a, BN_FLG_CONSTTIME); a->top = b->top; a->neg = b->neg; bn_check_top(a); return a; }
['static int rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value,\n BN_GENCB *cb)\n{\n BIGNUM *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *tmp;\n int bitsp, bitsq, ok = -1, n = 0;\n BN_CTX *ctx = NULL;\n if (bits < 16) {\n ok = 0;\n RSAerr(RSA_F_RSA_BUILTIN_KEYGEN, RSA_R_KEY_SIZE_TOO_SMALL);\n goto err;\n }\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n BN_CTX_start(ctx);\n r0 = BN_CTX_get(ctx);\n r1 = BN_CTX_get(ctx);\n r2 = BN_CTX_get(ctx);\n r3 = BN_CTX_get(ctx);\n if (r3 == NULL)\n goto err;\n bitsp = (bits + 1) / 2;\n bitsq = bits - bitsp;\n if (!rsa->n && ((rsa->n = BN_new()) == NULL))\n goto err;\n if (!rsa->d && ((rsa->d = BN_secure_new()) == NULL))\n goto err;\n if (!rsa->e && ((rsa->e = BN_new()) == NULL))\n goto err;\n if (!rsa->p && ((rsa->p = BN_secure_new()) == NULL))\n goto err;\n if (!rsa->q && ((rsa->q = BN_secure_new()) == NULL))\n goto err;\n if (!rsa->dmp1 && ((rsa->dmp1 = BN_secure_new()) == NULL))\n goto err;\n if (!rsa->dmq1 && ((rsa->dmq1 = BN_secure_new()) == NULL))\n goto err;\n if (!rsa->iqmp && ((rsa->iqmp = BN_secure_new()) == NULL))\n goto err;\n if (BN_copy(rsa->e, e_value) == NULL)\n goto err;\n for (;;) {\n if (!BN_generate_prime_ex(rsa->p, bitsp, 0, NULL, NULL, cb))\n goto err;\n if (!BN_sub(r2, rsa->p, BN_value_one()))\n goto err;\n if (!BN_gcd(r1, r2, rsa->e, ctx))\n goto err;\n if (BN_is_one(r1))\n break;\n if (!BN_GENCB_call(cb, 2, n++))\n goto err;\n }\n if (!BN_GENCB_call(cb, 3, 0))\n goto err;\n for (;;) {\n do {\n if (!BN_generate_prime_ex(rsa->q, bitsq, 0, NULL, NULL, cb))\n goto err;\n } while (BN_cmp(rsa->p, rsa->q) == 0);\n if (!BN_sub(r2, rsa->q, BN_value_one()))\n goto err;\n if (!BN_gcd(r1, r2, rsa->e, ctx))\n goto err;\n if (BN_is_one(r1))\n break;\n if (!BN_GENCB_call(cb, 2, n++))\n goto err;\n }\n if (!BN_GENCB_call(cb, 3, 1))\n goto err;\n if (BN_cmp(rsa->p, rsa->q) < 0) {\n tmp = rsa->p;\n rsa->p = rsa->q;\n rsa->q = tmp;\n }\n if (!BN_mul(rsa->n, rsa->p, rsa->q, ctx))\n goto err;\n if (!BN_sub(r1, rsa->p, BN_value_one()))\n goto err;\n if (!BN_sub(r2, rsa->q, BN_value_one()))\n goto err;\n if (!BN_mul(r0, r1, r2, ctx))\n goto err;\n {\n BIGNUM *pr0 = BN_new();\n if (pr0 == NULL)\n goto err;\n BN_with_flags(pr0, r0, BN_FLG_CONSTTIME);\n if (!BN_mod_inverse(rsa->d, rsa->e, pr0, ctx)) {\n BN_free(pr0);\n goto err;\n }\n BN_free(pr0);\n }\n {\n BIGNUM *d = BN_new();\n if (d == NULL)\n goto err;\n BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);\n if (\n !BN_mod(rsa->dmp1, d, r1, ctx)\n || !BN_mod(rsa->dmq1, d, r2, ctx)) {\n BN_free(d);\n goto err;\n }\n BN_free(d);\n }\n {\n BIGNUM *p = BN_new();\n if (p == NULL)\n goto err;\n BN_with_flags(p, rsa->p, BN_FLG_CONSTTIME);\n if (!BN_mod_inverse(rsa->iqmp, rsa->q, p, ctx)) {\n BN_free(p);\n goto err;\n }\n BN_free(p);\n }\n ok = 1;\n err:\n if (ok == -1) {\n RSAerr(RSA_F_RSA_BUILTIN_KEYGEN, ERR_LIB_BN);\n ok = 0;\n }\n if (ctx != NULL)\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n return ok;\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n bn_check_top(b);\n if (a == b)\n return a;\n if (bn_wexpand(a, b->top) == NULL)\n return NULL;\n if (b->top > 0)\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n if (BN_get_flags(b, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(a, BN_FLG_CONSTTIME);\n a->top = b->top;\n a->neg = b->neg;\n bn_check_top(a);\n return a;\n}', 'int BN_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx)\n{\n BIGNUM *a, *b, *t;\n int ret = 0;\n bn_check_top(in_a);\n bn_check_top(in_b);\n BN_CTX_start(ctx);\n a = BN_CTX_get(ctx);\n b = BN_CTX_get(ctx);\n if (b == NULL)\n goto err;\n if (BN_copy(a, in_a) == NULL)\n goto err;\n if (BN_copy(b, in_b) == NULL)\n goto err;\n a->neg = 0;\n b->neg = 0;\n if (BN_cmp(a, b) < 0) {\n t = a;\n a = b;\n b = t;\n }\n t = euclid(a, b);\n if (t == NULL)\n goto err;\n if (BN_copy(r, t) == NULL)\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n bn_check_top(r);\n return (ret);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
34,866
0
https://github.com/openssl/openssl/blob/47ddf355b46eae8c846e411f44531e928e04adf5/crypto/lhash/lhash.c/#L278
static void doall_util_fn(LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func, LHASH_DOALL_ARG_FN_TYPE func_arg, const void *arg) { int i; LHASH_NODE *a,*n; for (i=lh->num_nodes-1; i>=0; i--) { a=lh->b[i]; while (a != NULL) { n=a->next; if(use_arg) func_arg(a->data,arg); else func(a->data); a=n; } } }
['void OBJ_NAME_do_all(int type,void (*fn)(const OBJ_NAME *,void *arg),void *arg)\n\t{\n\tstruct doall d;\n\td.type=type;\n\td.fn=fn;\n\td.arg=arg;\n\tlh_doall_arg(names_lh,LHASH_DOALL_ARG_FN(do_all_fn),&d);\n\t}', 'void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, const void *arg)\n\t{\n\tdoall_util_fn(lh, 1, (LHASH_DOALL_FN_TYPE)0, func, arg);\n\t}', 'static void doall_util_fn(LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func,\n\t\t\tLHASH_DOALL_ARG_FN_TYPE func_arg, const void *arg)\n\t{\n\tint i;\n\tLHASH_NODE *a,*n;\n\tfor (i=lh->num_nodes-1; i>=0; i--)\n\t\t{\n\t\ta=lh->b[i];\n\t\twhile (a != NULL)\n\t\t\t{\n\t\t\tn=a->next;\n\t\t\tif(use_arg)\n\t\t\t\tfunc_arg(a->data,arg);\n\t\t\telse\n\t\t\t\tfunc(a->data);\n\t\t\ta=n;\n\t\t\t}\n\t\t}\n\t}']
34,867
0
https://github.com/openssl/openssl/blob/c67cdb50d2ef09c917c96d8a7e8a65d698ed9b8c/crypto/rsa/rsa_eay.c/#L420
static int RSA_eay_public_decrypt(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding) { const RSA_METHOD *meth; BIGNUM f,ret; int i,num=0,r= -1; unsigned char *p; unsigned char *buf=NULL; BN_CTX *ctx=NULL; meth = ENGINE_get_RSA(rsa->engine); BN_init(&f); BN_init(&ret); ctx=BN_CTX_new(); if (ctx == NULL) goto err; num=BN_num_bytes(rsa->n); buf=(unsigned char *)OPENSSL_malloc(num); if (buf == NULL) { RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,ERR_R_MALLOC_FAILURE); goto err; } if (flen > num) { RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN); goto err; } if (BN_bin2bn(from,flen,&f) == NULL) goto err; if ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC)) { BN_MONT_CTX* bn_mont_ctx; if ((bn_mont_ctx=BN_MONT_CTX_new()) == NULL) goto err; if (!BN_MONT_CTX_set(bn_mont_ctx,rsa->n,ctx)) { BN_MONT_CTX_free(bn_mont_ctx); goto err; } if (rsa->_method_mod_n == NULL) { CRYPTO_w_lock(CRYPTO_LOCK_RSA); if (rsa->_method_mod_n == NULL) { rsa->_method_mod_n = bn_mont_ctx; bn_mont_ctx = NULL; } CRYPTO_w_unlock(CRYPTO_LOCK_RSA); } if (bn_mont_ctx) BN_MONT_CTX_free(bn_mont_ctx); } if (!meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx, rsa->_method_mod_n)) goto err; p=buf; i=BN_bn2bin(&ret,p); switch (padding) { case RSA_PKCS1_PADDING: r=RSA_padding_check_PKCS1_type_1(to,num,buf,i,num); break; case RSA_NO_PADDING: r=RSA_padding_check_none(to,num,buf,i,num); break; default: RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE); goto err; } if (r < 0) RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_PADDING_CHECK_FAILED); err: if (ctx != NULL) BN_CTX_free(ctx); BN_clear_free(&f); BN_clear_free(&ret); if (buf != NULL) { memset(buf,0,num); OPENSSL_free(buf); } return(r); }
['static int RSA_eay_public_decrypt(int flen, const unsigned char *from,\n\t unsigned char *to, RSA *rsa, int padding)\n\t{\n\tconst RSA_METHOD *meth;\n\tBIGNUM f,ret;\n\tint i,num=0,r= -1;\n\tunsigned char *p;\n\tunsigned char *buf=NULL;\n\tBN_CTX *ctx=NULL;\n\tmeth = ENGINE_get_RSA(rsa->engine);\n\tBN_init(&f);\n\tBN_init(&ret);\n\tctx=BN_CTX_new();\n\tif (ctx == NULL) goto err;\n\tnum=BN_num_bytes(rsa->n);\n\tbuf=(unsigned char *)OPENSSL_malloc(num);\n\tif (buf == NULL)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tif (flen > num)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN);\n\t\tgoto err;\n\t\t}\n\tif (BN_bin2bn(from,flen,&f) == NULL) goto err;\n\tif ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC))\n\t\t{\n\t\tBN_MONT_CTX* bn_mont_ctx;\n\t\tif ((bn_mont_ctx=BN_MONT_CTX_new()) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_MONT_CTX_set(bn_mont_ctx,rsa->n,ctx))\n\t\t\t{\n\t\t\tBN_MONT_CTX_free(bn_mont_ctx);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (rsa->_method_mod_n == NULL)\n\t\t\t{\n\t\t\tCRYPTO_w_lock(CRYPTO_LOCK_RSA);\n\t\t\tif (rsa->_method_mod_n == NULL)\n\t\t\t\t{\n\t\t\t\trsa->_method_mod_n = bn_mont_ctx;\n\t\t\t\tbn_mont_ctx = NULL;\n\t\t\t\t}\n\t\t\tCRYPTO_w_unlock(CRYPTO_LOCK_RSA);\n\t\t\t}\n\t\tif (bn_mont_ctx)\n\t\t\tBN_MONT_CTX_free(bn_mont_ctx);\n\t\t}\n\tif (!meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx,\n\t\trsa->_method_mod_n)) goto err;\n\tp=buf;\n\ti=BN_bn2bin(&ret,p);\n\tswitch (padding)\n\t\t{\n\tcase RSA_PKCS1_PADDING:\n\t\tr=RSA_padding_check_PKCS1_type_1(to,num,buf,i,num);\n\t\tbreak;\n\tcase RSA_NO_PADDING:\n\t\tr=RSA_padding_check_none(to,num,buf,i,num);\n\t\tbreak;\n\tdefault:\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE);\n\t\tgoto err;\n\t\t}\n\tif (r < 0)\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_PADDING_CHECK_FAILED);\nerr:\n\tif (ctx != NULL) BN_CTX_free(ctx);\n\tBN_clear_free(&f);\n\tBN_clear_free(&ret);\n\tif (buf != NULL)\n\t\t{\n\t\tmemset(buf,0,num);\n\t\tOPENSSL_free(buf);\n\t\t}\n\treturn(r);\n\t}', 'const RSA_METHOD *ENGINE_get_RSA(ENGINE *e)\n\t{\n\tif(e == NULL)\n\t\t{\n\t\tENGINEerr(ENGINE_F_ENGINE_GET_RSA,\n\t\t\tERR_R_PASSED_NULL_PARAMETER);\n\t\treturn NULL;\n\t\t}\n\treturn e->rsa_meth;\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}', 'void BN_init(BIGNUM *a)\n\t{\n\tmemset(a,0,sizeof(BIGNUM));\n\t}', 'BN_CTX *BN_CTX_new(void)\n\t{\n\tBN_CTX *ret;\n\tret=(BN_CTX *)OPENSSL_malloc(sizeof(BN_CTX));\n\tif (ret == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tBN_CTX_init(ret);\n\tret->flags=BN_FLG_MALLOCED;\n\treturn(ret);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n\treturn ret;\n\t}', 'int BN_num_bits(const BIGNUM *a)\n\t{\n\tBN_ULONG l;\n\tint i;\n\tbn_check_top(a);\n\tif (a->top == 0) return(0);\n\tl=a->d[a->top-1];\n\tassert(l != 0);\n\ti=(a->top-1)*BN_BITS2;\n\treturn(i+BN_num_bits_word(l));\n\t}']
34,868
1
https://github.com/libav/libav/blob/1a07df31128da3a0020b66502399989b91770d44/libavcodec/mpegvideo_enc.c/#L2958
static int encode_thread(AVCodecContext *c, void *arg){ MpegEncContext *s= *(void**)arg; int mb_x, mb_y, pdif = 0; int chr_h= 16>>s->chroma_y_shift; int i, j; MpegEncContext best_s, backup_s; uint8_t bit_buf[2][MAX_MB_BYTES]; uint8_t bit_buf2[2][MAX_MB_BYTES]; uint8_t bit_buf_tex[2][MAX_MB_BYTES]; PutBitContext pb[2], pb2[2], tex_pb[2]; for(i=0; i<2; i++){ init_put_bits(&pb [i], bit_buf [i], MAX_MB_BYTES); init_put_bits(&pb2 [i], bit_buf2 [i], MAX_MB_BYTES); init_put_bits(&tex_pb[i], bit_buf_tex[i], MAX_MB_BYTES); } s->last_bits= put_bits_count(&s->pb); s->mv_bits=0; s->misc_bits=0; s->i_tex_bits=0; s->p_tex_bits=0; s->i_count=0; s->f_count=0; s->b_count=0; s->skip_count=0; for(i=0; i<3; i++){ s->last_dc[i] = 128 << s->intra_dc_precision; s->current_picture.f->error[i] = 0; } s->mb_skip_run = 0; memset(s->last_mv, 0, sizeof(s->last_mv)); s->last_mv_dir = 0; switch(s->codec_id){ case AV_CODEC_ID_H263: case AV_CODEC_ID_H263P: case AV_CODEC_ID_FLV1: if (CONFIG_H263_ENCODER) s->gob_index = ff_h263_get_gob_height(s); break; case AV_CODEC_ID_MPEG4: if(CONFIG_MPEG4_ENCODER && s->partitioned_frame) ff_mpeg4_init_partitions(s); break; } s->resync_mb_x=0; s->resync_mb_y=0; s->first_slice_line = 1; s->ptr_lastgob = s->pb.buf; for(mb_y= s->start_mb_y; mb_y < s->end_mb_y; mb_y++) { s->mb_x=0; s->mb_y= mb_y; ff_set_qscale(s, s->qscale); ff_init_block_index(s); for(mb_x=0; mb_x < s->mb_width; mb_x++) { int xy= mb_y*s->mb_stride + mb_x; int mb_type= s->mb_type[xy]; int dmin= INT_MAX; int dir; if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < MAX_MB_BYTES){ av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); return -1; } if(s->data_partitioning){ if( s->pb2 .buf_end - s->pb2 .buf - (put_bits_count(&s-> pb2)>>3) < MAX_MB_BYTES || s->tex_pb.buf_end - s->tex_pb.buf - (put_bits_count(&s->tex_pb )>>3) < MAX_MB_BYTES){ av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); return -1; } } s->mb_x = mb_x; s->mb_y = mb_y; ff_update_block_index(s); if(CONFIG_H261_ENCODER && s->codec_id == AV_CODEC_ID_H261){ ff_h261_reorder_mb_index(s); xy= s->mb_y*s->mb_stride + s->mb_x; mb_type= s->mb_type[xy]; } if(s->rtp_mode){ int current_packet_size, is_gob_start; current_packet_size= ((put_bits_count(&s->pb)+7)>>3) - (s->ptr_lastgob - s->pb.buf); is_gob_start= s->avctx->rtp_payload_size && current_packet_size >= s->avctx->rtp_payload_size && mb_y + mb_x>0; if(s->start_mb_y == mb_y && mb_y > 0 && mb_x==0) is_gob_start=1; switch(s->codec_id){ case AV_CODEC_ID_H263: case AV_CODEC_ID_H263P: if(!s->h263_slice_structured) if(s->mb_x || s->mb_y%s->gob_index) is_gob_start=0; break; case AV_CODEC_ID_MPEG2VIDEO: if(s->mb_x==0 && s->mb_y!=0) is_gob_start=1; case AV_CODEC_ID_MPEG1VIDEO: if(s->mb_skip_run) is_gob_start=0; break; } if(is_gob_start){ if(s->start_mb_y != mb_y || mb_x!=0){ write_slice_end(s); if(CONFIG_MPEG4_ENCODER && s->codec_id==AV_CODEC_ID_MPEG4 && s->partitioned_frame){ ff_mpeg4_init_partitions(s); } } assert((put_bits_count(&s->pb)&7) == 0); current_packet_size= put_bits_ptr(&s->pb) - s->ptr_lastgob; if (s->error_rate && s->resync_mb_x + s->resync_mb_y > 0) { int r= put_bits_count(&s->pb)/8 + s->picture_number + 16 + s->mb_x + s->mb_y; int d = 100 / s->error_rate; if(r % d == 0){ current_packet_size=0; s->pb.buf_ptr= s->ptr_lastgob; assert(put_bits_ptr(&s->pb) == s->ptr_lastgob); } } if (s->avctx->rtp_callback){ int number_mb = (mb_y - s->resync_mb_y)*s->mb_width + mb_x - s->resync_mb_x; s->avctx->rtp_callback(s->avctx, s->ptr_lastgob, current_packet_size, number_mb); } update_mb_info(s, 1); switch(s->codec_id){ case AV_CODEC_ID_MPEG4: if (CONFIG_MPEG4_ENCODER) { ff_mpeg4_encode_video_packet_header(s); ff_mpeg4_clean_buffers(s); } break; case AV_CODEC_ID_MPEG1VIDEO: case AV_CODEC_ID_MPEG2VIDEO: if (CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER) { ff_mpeg1_encode_slice_header(s); ff_mpeg1_clean_buffers(s); } break; case AV_CODEC_ID_H263: case AV_CODEC_ID_H263P: if (CONFIG_H263_ENCODER) ff_h263_encode_gob_header(s, mb_y); break; } if(s->flags&CODEC_FLAG_PASS1){ int bits= put_bits_count(&s->pb); s->misc_bits+= bits - s->last_bits; s->last_bits= bits; } s->ptr_lastgob += current_packet_size; s->first_slice_line=1; s->resync_mb_x=mb_x; s->resync_mb_y=mb_y; } } if( (s->resync_mb_x == s->mb_x) && s->resync_mb_y+1 == s->mb_y){ s->first_slice_line=0; } s->mb_skipped=0; s->dquant=0; update_mb_info(s, 0); if (mb_type & (mb_type-1) || (s->mpv_flags & FF_MPV_FLAG_QP_RD)) { int next_block=0; int pb_bits_count, pb2_bits_count, tex_pb_bits_count; copy_context_before_encode(&backup_s, s, -1); backup_s.pb= s->pb; best_s.data_partitioning= s->data_partitioning; best_s.partitioned_frame= s->partitioned_frame; if(s->data_partitioning){ backup_s.pb2= s->pb2; backup_s.tex_pb= s->tex_pb; } if(mb_type&CANDIDATE_MB_TYPE_INTER){ s->mv_dir = MV_DIR_FORWARD; s->mv_type = MV_TYPE_16X16; s->mb_intra= 0; s->mv[0][0][0] = s->p_mv_table[xy][0]; s->mv[0][0][1] = s->p_mv_table[xy][1]; encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER, pb, pb2, tex_pb, &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); } if(mb_type&CANDIDATE_MB_TYPE_INTER_I){ s->mv_dir = MV_DIR_FORWARD; s->mv_type = MV_TYPE_FIELD; s->mb_intra= 0; for(i=0; i<2; i++){ j= s->field_select[0][i] = s->p_field_select_table[i][xy]; s->mv[0][i][0] = s->p_field_mv_table[i][j][xy][0]; s->mv[0][i][1] = s->p_field_mv_table[i][j][xy][1]; } encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER_I, pb, pb2, tex_pb, &dmin, &next_block, 0, 0); } if(mb_type&CANDIDATE_MB_TYPE_SKIPPED){ s->mv_dir = MV_DIR_FORWARD; s->mv_type = MV_TYPE_16X16; s->mb_intra= 0; s->mv[0][0][0] = 0; s->mv[0][0][1] = 0; encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_SKIPPED, pb, pb2, tex_pb, &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); } if(mb_type&CANDIDATE_MB_TYPE_INTER4V){ s->mv_dir = MV_DIR_FORWARD; s->mv_type = MV_TYPE_8X8; s->mb_intra= 0; for(i=0; i<4; i++){ s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0]; s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1]; } encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER4V, pb, pb2, tex_pb, &dmin, &next_block, 0, 0); } if(mb_type&CANDIDATE_MB_TYPE_FORWARD){ s->mv_dir = MV_DIR_FORWARD; s->mv_type = MV_TYPE_16X16; s->mb_intra= 0; s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_FORWARD, pb, pb2, tex_pb, &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); } if(mb_type&CANDIDATE_MB_TYPE_BACKWARD){ s->mv_dir = MV_DIR_BACKWARD; s->mv_type = MV_TYPE_16X16; s->mb_intra= 0; s->mv[1][0][0] = s->b_back_mv_table[xy][0]; s->mv[1][0][1] = s->b_back_mv_table[xy][1]; encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BACKWARD, pb, pb2, tex_pb, &dmin, &next_block, s->mv[1][0][0], s->mv[1][0][1]); } if(mb_type&CANDIDATE_MB_TYPE_BIDIR){ s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; s->mv_type = MV_TYPE_16X16; s->mb_intra= 0; s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BIDIR, pb, pb2, tex_pb, &dmin, &next_block, 0, 0); } if(mb_type&CANDIDATE_MB_TYPE_FORWARD_I){ s->mv_dir = MV_DIR_FORWARD; s->mv_type = MV_TYPE_FIELD; s->mb_intra= 0; for(i=0; i<2; i++){ j= s->field_select[0][i] = s->b_field_select_table[0][i][xy]; s->mv[0][i][0] = s->b_field_mv_table[0][i][j][xy][0]; s->mv[0][i][1] = s->b_field_mv_table[0][i][j][xy][1]; } encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_FORWARD_I, pb, pb2, tex_pb, &dmin, &next_block, 0, 0); } if(mb_type&CANDIDATE_MB_TYPE_BACKWARD_I){ s->mv_dir = MV_DIR_BACKWARD; s->mv_type = MV_TYPE_FIELD; s->mb_intra= 0; for(i=0; i<2; i++){ j= s->field_select[1][i] = s->b_field_select_table[1][i][xy]; s->mv[1][i][0] = s->b_field_mv_table[1][i][j][xy][0]; s->mv[1][i][1] = s->b_field_mv_table[1][i][j][xy][1]; } encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BACKWARD_I, pb, pb2, tex_pb, &dmin, &next_block, 0, 0); } if(mb_type&CANDIDATE_MB_TYPE_BIDIR_I){ s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; s->mv_type = MV_TYPE_FIELD; s->mb_intra= 0; for(dir=0; dir<2; dir++){ for(i=0; i<2; i++){ j= s->field_select[dir][i] = s->b_field_select_table[dir][i][xy]; s->mv[dir][i][0] = s->b_field_mv_table[dir][i][j][xy][0]; s->mv[dir][i][1] = s->b_field_mv_table[dir][i][j][xy][1]; } } encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BIDIR_I, pb, pb2, tex_pb, &dmin, &next_block, 0, 0); } if(mb_type&CANDIDATE_MB_TYPE_INTRA){ s->mv_dir = 0; s->mv_type = MV_TYPE_16X16; s->mb_intra= 1; s->mv[0][0][0] = 0; s->mv[0][0][1] = 0; encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTRA, pb, pb2, tex_pb, &dmin, &next_block, 0, 0); if(s->h263_pred || s->h263_aic){ if(best_s.mb_intra) s->mbintra_table[mb_x + mb_y*s->mb_stride]=1; else ff_clean_intra_table_entries(s); } } if ((s->mpv_flags & FF_MPV_FLAG_QP_RD) && dmin < INT_MAX) { if(best_s.mv_type==MV_TYPE_16X16){ const int last_qp= backup_s.qscale; int qpi, qp, dc[6]; int16_t ac[6][16]; const int mvdir= (best_s.mv_dir&MV_DIR_BACKWARD) ? 1 : 0; static const int dquant_tab[4]={-1,1,-2,2}; assert(backup_s.dquant == 0); s->mv_dir= best_s.mv_dir; s->mv_type = MV_TYPE_16X16; s->mb_intra= best_s.mb_intra; s->mv[0][0][0] = best_s.mv[0][0][0]; s->mv[0][0][1] = best_s.mv[0][0][1]; s->mv[1][0][0] = best_s.mv[1][0][0]; s->mv[1][0][1] = best_s.mv[1][0][1]; qpi = s->pict_type == AV_PICTURE_TYPE_B ? 2 : 0; for(; qpi<4; qpi++){ int dquant= dquant_tab[qpi]; qp= last_qp + dquant; if(qp < s->avctx->qmin || qp > s->avctx->qmax) continue; backup_s.dquant= dquant; if(s->mb_intra && s->dc_val[0]){ for(i=0; i<6; i++){ dc[i]= s->dc_val[0][ s->block_index[i] ]; memcpy(ac[i], s->ac_val[0][s->block_index[i]], sizeof(int16_t)*16); } } encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER , pb, pb2, tex_pb, &dmin, &next_block, s->mv[mvdir][0][0], s->mv[mvdir][0][1]); if(best_s.qscale != qp){ if(s->mb_intra && s->dc_val[0]){ for(i=0; i<6; i++){ s->dc_val[0][ s->block_index[i] ]= dc[i]; memcpy(s->ac_val[0][s->block_index[i]], ac[i], sizeof(int16_t)*16); } } } } } } if(CONFIG_MPEG4_ENCODER && mb_type&CANDIDATE_MB_TYPE_DIRECT){ int mx= s->b_direct_mv_table[xy][0]; int my= s->b_direct_mv_table[xy][1]; backup_s.dquant = 0; s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; s->mb_intra= 0; ff_mpeg4_set_direct_mv(s, mx, my); encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb, &dmin, &next_block, mx, my); } if(CONFIG_MPEG4_ENCODER && mb_type&CANDIDATE_MB_TYPE_DIRECT0){ backup_s.dquant = 0; s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; s->mb_intra= 0; ff_mpeg4_set_direct_mv(s, 0, 0); encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb, &dmin, &next_block, 0, 0); } if (!best_s.mb_intra && s->mpv_flags & FF_MPV_FLAG_SKIP_RD) { int coded=0; for(i=0; i<6; i++) coded |= s->block_last_index[i]; if(coded){ int mx,my; memcpy(s->mv, best_s.mv, sizeof(s->mv)); if(CONFIG_MPEG4_ENCODER && best_s.mv_dir & MV_DIRECT){ mx=my=0; ff_mpeg4_set_direct_mv(s, mx, my); }else if(best_s.mv_dir&MV_DIR_BACKWARD){ mx= s->mv[1][0][0]; my= s->mv[1][0][1]; }else{ mx= s->mv[0][0][0]; my= s->mv[0][0][1]; } s->mv_dir= best_s.mv_dir; s->mv_type = best_s.mv_type; s->mb_intra= 0; backup_s.dquant= 0; s->skipdct=1; encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER , pb, pb2, tex_pb, &dmin, &next_block, mx, my); s->skipdct=0; } } s->current_picture.qscale_table[xy] = best_s.qscale; copy_context_after_encode(s, &best_s, -1); pb_bits_count= put_bits_count(&s->pb); flush_put_bits(&s->pb); avpriv_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count); s->pb= backup_s.pb; if(s->data_partitioning){ pb2_bits_count= put_bits_count(&s->pb2); flush_put_bits(&s->pb2); avpriv_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count); s->pb2= backup_s.pb2; tex_pb_bits_count= put_bits_count(&s->tex_pb); flush_put_bits(&s->tex_pb); avpriv_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count); s->tex_pb= backup_s.tex_pb; } s->last_bits= put_bits_count(&s->pb); if (CONFIG_H263_ENCODER && s->out_format == FMT_H263 && s->pict_type!=AV_PICTURE_TYPE_B) ff_h263_update_motion_val(s); if(next_block==0){ s->hdsp.put_pixels_tab[0][0](s->dest[0], s->rd_scratchpad , s->linesize ,16); s->hdsp.put_pixels_tab[1][0](s->dest[1], s->rd_scratchpad + 16*s->linesize , s->uvlinesize, 8); s->hdsp.put_pixels_tab[1][0](s->dest[2], s->rd_scratchpad + 16*s->linesize + 8, s->uvlinesize, 8); } if(s->avctx->mb_decision == FF_MB_DECISION_BITS) ff_mpv_decode_mb(s, s->block); } else { int motion_x = 0, motion_y = 0; s->mv_type=MV_TYPE_16X16; switch(mb_type){ case CANDIDATE_MB_TYPE_INTRA: s->mv_dir = 0; s->mb_intra= 1; motion_x= s->mv[0][0][0] = 0; motion_y= s->mv[0][0][1] = 0; break; case CANDIDATE_MB_TYPE_INTER: s->mv_dir = MV_DIR_FORWARD; s->mb_intra= 0; motion_x= s->mv[0][0][0] = s->p_mv_table[xy][0]; motion_y= s->mv[0][0][1] = s->p_mv_table[xy][1]; break; case CANDIDATE_MB_TYPE_INTER_I: s->mv_dir = MV_DIR_FORWARD; s->mv_type = MV_TYPE_FIELD; s->mb_intra= 0; for(i=0; i<2; i++){ j= s->field_select[0][i] = s->p_field_select_table[i][xy]; s->mv[0][i][0] = s->p_field_mv_table[i][j][xy][0]; s->mv[0][i][1] = s->p_field_mv_table[i][j][xy][1]; } break; case CANDIDATE_MB_TYPE_INTER4V: s->mv_dir = MV_DIR_FORWARD; s->mv_type = MV_TYPE_8X8; s->mb_intra= 0; for(i=0; i<4; i++){ s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0]; s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1]; } break; case CANDIDATE_MB_TYPE_DIRECT: if (CONFIG_MPEG4_ENCODER) { s->mv_dir = MV_DIR_FORWARD|MV_DIR_BACKWARD|MV_DIRECT; s->mb_intra= 0; motion_x=s->b_direct_mv_table[xy][0]; motion_y=s->b_direct_mv_table[xy][1]; ff_mpeg4_set_direct_mv(s, motion_x, motion_y); } break; case CANDIDATE_MB_TYPE_DIRECT0: if (CONFIG_MPEG4_ENCODER) { s->mv_dir = MV_DIR_FORWARD|MV_DIR_BACKWARD|MV_DIRECT; s->mb_intra= 0; ff_mpeg4_set_direct_mv(s, 0, 0); } break; case CANDIDATE_MB_TYPE_BIDIR: s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; s->mb_intra= 0; s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; break; case CANDIDATE_MB_TYPE_BACKWARD: s->mv_dir = MV_DIR_BACKWARD; s->mb_intra= 0; motion_x= s->mv[1][0][0] = s->b_back_mv_table[xy][0]; motion_y= s->mv[1][0][1] = s->b_back_mv_table[xy][1]; break; case CANDIDATE_MB_TYPE_FORWARD: s->mv_dir = MV_DIR_FORWARD; s->mb_intra= 0; motion_x= s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; motion_y= s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; break; case CANDIDATE_MB_TYPE_FORWARD_I: s->mv_dir = MV_DIR_FORWARD; s->mv_type = MV_TYPE_FIELD; s->mb_intra= 0; for(i=0; i<2; i++){ j= s->field_select[0][i] = s->b_field_select_table[0][i][xy]; s->mv[0][i][0] = s->b_field_mv_table[0][i][j][xy][0]; s->mv[0][i][1] = s->b_field_mv_table[0][i][j][xy][1]; } break; case CANDIDATE_MB_TYPE_BACKWARD_I: s->mv_dir = MV_DIR_BACKWARD; s->mv_type = MV_TYPE_FIELD; s->mb_intra= 0; for(i=0; i<2; i++){ j= s->field_select[1][i] = s->b_field_select_table[1][i][xy]; s->mv[1][i][0] = s->b_field_mv_table[1][i][j][xy][0]; s->mv[1][i][1] = s->b_field_mv_table[1][i][j][xy][1]; } break; case CANDIDATE_MB_TYPE_BIDIR_I: s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; s->mv_type = MV_TYPE_FIELD; s->mb_intra= 0; for(dir=0; dir<2; dir++){ for(i=0; i<2; i++){ j= s->field_select[dir][i] = s->b_field_select_table[dir][i][xy]; s->mv[dir][i][0] = s->b_field_mv_table[dir][i][j][xy][0]; s->mv[dir][i][1] = s->b_field_mv_table[dir][i][j][xy][1]; } } break; default: av_log(s->avctx, AV_LOG_ERROR, "illegal MB type\n"); } encode_mb(s, motion_x, motion_y); s->last_mv_dir = s->mv_dir; if (CONFIG_H263_ENCODER && s->out_format == FMT_H263 && s->pict_type!=AV_PICTURE_TYPE_B) ff_h263_update_motion_val(s); ff_mpv_decode_mb(s, s->block); } if(s->mb_intra ){ s->p_mv_table[xy][0]=0; s->p_mv_table[xy][1]=0; } if(s->flags&CODEC_FLAG_PSNR){ int w= 16; int h= 16; if(s->mb_x*16 + 16 > s->width ) w= s->width - s->mb_x*16; if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16; s->current_picture.f->error[0] += sse( s, s->new_picture.f->data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], w, h, s->linesize); s->current_picture.f->error[1] += sse( s, s->new_picture.f->data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*chr_h, s->dest[1], w>>1, h>>s->chroma_y_shift, s->uvlinesize); s->current_picture.f->error[2] += sse( s, s->new_picture.f->data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*chr_h, s->dest[2], w>>1, h>>s->chroma_y_shift, s->uvlinesize); } if(s->loop_filter){ if(CONFIG_H263_ENCODER && s->out_format == FMT_H263) ff_h263_loop_filter(s); } av_dlog(s->avctx, "MB %d %d bits\n", s->mb_x + s->mb_y * s->mb_stride, put_bits_count(&s->pb)); } } if (CONFIG_MSMPEG4_ENCODER && s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type == AV_PICTURE_TYPE_I) ff_msmpeg4_encode_ext_header(s); write_slice_end(s); if (s->avctx->rtp_callback) { int number_mb = (mb_y - s->resync_mb_y)*s->mb_width - s->resync_mb_x; pdif = put_bits_ptr(&s->pb) - s->ptr_lastgob; emms_c(); s->avctx->rtp_callback(s->avctx, s->ptr_lastgob, pdif, number_mb); } return 0; }
['static int encode_thread(AVCodecContext *c, void *arg){\n MpegEncContext *s= *(void**)arg;\n int mb_x, mb_y, pdif = 0;\n int chr_h= 16>>s->chroma_y_shift;\n int i, j;\n MpegEncContext best_s, backup_s;\n uint8_t bit_buf[2][MAX_MB_BYTES];\n uint8_t bit_buf2[2][MAX_MB_BYTES];\n uint8_t bit_buf_tex[2][MAX_MB_BYTES];\n PutBitContext pb[2], pb2[2], tex_pb[2];\n for(i=0; i<2; i++){\n init_put_bits(&pb [i], bit_buf [i], MAX_MB_BYTES);\n init_put_bits(&pb2 [i], bit_buf2 [i], MAX_MB_BYTES);\n init_put_bits(&tex_pb[i], bit_buf_tex[i], MAX_MB_BYTES);\n }\n s->last_bits= put_bits_count(&s->pb);\n s->mv_bits=0;\n s->misc_bits=0;\n s->i_tex_bits=0;\n s->p_tex_bits=0;\n s->i_count=0;\n s->f_count=0;\n s->b_count=0;\n s->skip_count=0;\n for(i=0; i<3; i++){\n s->last_dc[i] = 128 << s->intra_dc_precision;\n s->current_picture.f->error[i] = 0;\n }\n s->mb_skip_run = 0;\n memset(s->last_mv, 0, sizeof(s->last_mv));\n s->last_mv_dir = 0;\n switch(s->codec_id){\n case AV_CODEC_ID_H263:\n case AV_CODEC_ID_H263P:\n case AV_CODEC_ID_FLV1:\n if (CONFIG_H263_ENCODER)\n s->gob_index = ff_h263_get_gob_height(s);\n break;\n case AV_CODEC_ID_MPEG4:\n if(CONFIG_MPEG4_ENCODER && s->partitioned_frame)\n ff_mpeg4_init_partitions(s);\n break;\n }\n s->resync_mb_x=0;\n s->resync_mb_y=0;\n s->first_slice_line = 1;\n s->ptr_lastgob = s->pb.buf;\n for(mb_y= s->start_mb_y; mb_y < s->end_mb_y; mb_y++) {\n s->mb_x=0;\n s->mb_y= mb_y;\n ff_set_qscale(s, s->qscale);\n ff_init_block_index(s);\n for(mb_x=0; mb_x < s->mb_width; mb_x++) {\n int xy= mb_y*s->mb_stride + mb_x;\n int mb_type= s->mb_type[xy];\n int dmin= INT_MAX;\n int dir;\n if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < MAX_MB_BYTES){\n av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\\n");\n return -1;\n }\n if(s->data_partitioning){\n if( s->pb2 .buf_end - s->pb2 .buf - (put_bits_count(&s-> pb2)>>3) < MAX_MB_BYTES\n || s->tex_pb.buf_end - s->tex_pb.buf - (put_bits_count(&s->tex_pb )>>3) < MAX_MB_BYTES){\n av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\\n");\n return -1;\n }\n }\n s->mb_x = mb_x;\n s->mb_y = mb_y;\n ff_update_block_index(s);\n if(CONFIG_H261_ENCODER && s->codec_id == AV_CODEC_ID_H261){\n ff_h261_reorder_mb_index(s);\n xy= s->mb_y*s->mb_stride + s->mb_x;\n mb_type= s->mb_type[xy];\n }\n if(s->rtp_mode){\n int current_packet_size, is_gob_start;\n current_packet_size= ((put_bits_count(&s->pb)+7)>>3) - (s->ptr_lastgob - s->pb.buf);\n is_gob_start= s->avctx->rtp_payload_size && current_packet_size >= s->avctx->rtp_payload_size && mb_y + mb_x>0;\n if(s->start_mb_y == mb_y && mb_y > 0 && mb_x==0) is_gob_start=1;\n switch(s->codec_id){\n case AV_CODEC_ID_H263:\n case AV_CODEC_ID_H263P:\n if(!s->h263_slice_structured)\n if(s->mb_x || s->mb_y%s->gob_index) is_gob_start=0;\n break;\n case AV_CODEC_ID_MPEG2VIDEO:\n if(s->mb_x==0 && s->mb_y!=0) is_gob_start=1;\n case AV_CODEC_ID_MPEG1VIDEO:\n if(s->mb_skip_run) is_gob_start=0;\n break;\n }\n if(is_gob_start){\n if(s->start_mb_y != mb_y || mb_x!=0){\n write_slice_end(s);\n if(CONFIG_MPEG4_ENCODER && s->codec_id==AV_CODEC_ID_MPEG4 && s->partitioned_frame){\n ff_mpeg4_init_partitions(s);\n }\n }\n assert((put_bits_count(&s->pb)&7) == 0);\n current_packet_size= put_bits_ptr(&s->pb) - s->ptr_lastgob;\n if (s->error_rate && s->resync_mb_x + s->resync_mb_y > 0) {\n int r= put_bits_count(&s->pb)/8 + s->picture_number + 16 + s->mb_x + s->mb_y;\n int d = 100 / s->error_rate;\n if(r % d == 0){\n current_packet_size=0;\n s->pb.buf_ptr= s->ptr_lastgob;\n assert(put_bits_ptr(&s->pb) == s->ptr_lastgob);\n }\n }\n if (s->avctx->rtp_callback){\n int number_mb = (mb_y - s->resync_mb_y)*s->mb_width + mb_x - s->resync_mb_x;\n s->avctx->rtp_callback(s->avctx, s->ptr_lastgob, current_packet_size, number_mb);\n }\n update_mb_info(s, 1);\n switch(s->codec_id){\n case AV_CODEC_ID_MPEG4:\n if (CONFIG_MPEG4_ENCODER) {\n ff_mpeg4_encode_video_packet_header(s);\n ff_mpeg4_clean_buffers(s);\n }\n break;\n case AV_CODEC_ID_MPEG1VIDEO:\n case AV_CODEC_ID_MPEG2VIDEO:\n if (CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER) {\n ff_mpeg1_encode_slice_header(s);\n ff_mpeg1_clean_buffers(s);\n }\n break;\n case AV_CODEC_ID_H263:\n case AV_CODEC_ID_H263P:\n if (CONFIG_H263_ENCODER)\n ff_h263_encode_gob_header(s, mb_y);\n break;\n }\n if(s->flags&CODEC_FLAG_PASS1){\n int bits= put_bits_count(&s->pb);\n s->misc_bits+= bits - s->last_bits;\n s->last_bits= bits;\n }\n s->ptr_lastgob += current_packet_size;\n s->first_slice_line=1;\n s->resync_mb_x=mb_x;\n s->resync_mb_y=mb_y;\n }\n }\n if( (s->resync_mb_x == s->mb_x)\n && s->resync_mb_y+1 == s->mb_y){\n s->first_slice_line=0;\n }\n s->mb_skipped=0;\n s->dquant=0;\n update_mb_info(s, 0);\n if (mb_type & (mb_type-1) || (s->mpv_flags & FF_MPV_FLAG_QP_RD)) {\n int next_block=0;\n int pb_bits_count, pb2_bits_count, tex_pb_bits_count;\n copy_context_before_encode(&backup_s, s, -1);\n backup_s.pb= s->pb;\n best_s.data_partitioning= s->data_partitioning;\n best_s.partitioned_frame= s->partitioned_frame;\n if(s->data_partitioning){\n backup_s.pb2= s->pb2;\n backup_s.tex_pb= s->tex_pb;\n }\n if(mb_type&CANDIDATE_MB_TYPE_INTER){\n s->mv_dir = MV_DIR_FORWARD;\n s->mv_type = MV_TYPE_16X16;\n s->mb_intra= 0;\n s->mv[0][0][0] = s->p_mv_table[xy][0];\n s->mv[0][0][1] = s->p_mv_table[xy][1];\n encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER, pb, pb2, tex_pb,\n &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]);\n }\n if(mb_type&CANDIDATE_MB_TYPE_INTER_I){\n s->mv_dir = MV_DIR_FORWARD;\n s->mv_type = MV_TYPE_FIELD;\n s->mb_intra= 0;\n for(i=0; i<2; i++){\n j= s->field_select[0][i] = s->p_field_select_table[i][xy];\n s->mv[0][i][0] = s->p_field_mv_table[i][j][xy][0];\n s->mv[0][i][1] = s->p_field_mv_table[i][j][xy][1];\n }\n encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER_I, pb, pb2, tex_pb,\n &dmin, &next_block, 0, 0);\n }\n if(mb_type&CANDIDATE_MB_TYPE_SKIPPED){\n s->mv_dir = MV_DIR_FORWARD;\n s->mv_type = MV_TYPE_16X16;\n s->mb_intra= 0;\n s->mv[0][0][0] = 0;\n s->mv[0][0][1] = 0;\n encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_SKIPPED, pb, pb2, tex_pb,\n &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]);\n }\n if(mb_type&CANDIDATE_MB_TYPE_INTER4V){\n s->mv_dir = MV_DIR_FORWARD;\n s->mv_type = MV_TYPE_8X8;\n s->mb_intra= 0;\n for(i=0; i<4; i++){\n s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0];\n s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1];\n }\n encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER4V, pb, pb2, tex_pb,\n &dmin, &next_block, 0, 0);\n }\n if(mb_type&CANDIDATE_MB_TYPE_FORWARD){\n s->mv_dir = MV_DIR_FORWARD;\n s->mv_type = MV_TYPE_16X16;\n s->mb_intra= 0;\n s->mv[0][0][0] = s->b_forw_mv_table[xy][0];\n s->mv[0][0][1] = s->b_forw_mv_table[xy][1];\n encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_FORWARD, pb, pb2, tex_pb,\n &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]);\n }\n if(mb_type&CANDIDATE_MB_TYPE_BACKWARD){\n s->mv_dir = MV_DIR_BACKWARD;\n s->mv_type = MV_TYPE_16X16;\n s->mb_intra= 0;\n s->mv[1][0][0] = s->b_back_mv_table[xy][0];\n s->mv[1][0][1] = s->b_back_mv_table[xy][1];\n encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BACKWARD, pb, pb2, tex_pb,\n &dmin, &next_block, s->mv[1][0][0], s->mv[1][0][1]);\n }\n if(mb_type&CANDIDATE_MB_TYPE_BIDIR){\n s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;\n s->mv_type = MV_TYPE_16X16;\n s->mb_intra= 0;\n s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0];\n s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1];\n s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0];\n s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1];\n encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BIDIR, pb, pb2, tex_pb,\n &dmin, &next_block, 0, 0);\n }\n if(mb_type&CANDIDATE_MB_TYPE_FORWARD_I){\n s->mv_dir = MV_DIR_FORWARD;\n s->mv_type = MV_TYPE_FIELD;\n s->mb_intra= 0;\n for(i=0; i<2; i++){\n j= s->field_select[0][i] = s->b_field_select_table[0][i][xy];\n s->mv[0][i][0] = s->b_field_mv_table[0][i][j][xy][0];\n s->mv[0][i][1] = s->b_field_mv_table[0][i][j][xy][1];\n }\n encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_FORWARD_I, pb, pb2, tex_pb,\n &dmin, &next_block, 0, 0);\n }\n if(mb_type&CANDIDATE_MB_TYPE_BACKWARD_I){\n s->mv_dir = MV_DIR_BACKWARD;\n s->mv_type = MV_TYPE_FIELD;\n s->mb_intra= 0;\n for(i=0; i<2; i++){\n j= s->field_select[1][i] = s->b_field_select_table[1][i][xy];\n s->mv[1][i][0] = s->b_field_mv_table[1][i][j][xy][0];\n s->mv[1][i][1] = s->b_field_mv_table[1][i][j][xy][1];\n }\n encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BACKWARD_I, pb, pb2, tex_pb,\n &dmin, &next_block, 0, 0);\n }\n if(mb_type&CANDIDATE_MB_TYPE_BIDIR_I){\n s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;\n s->mv_type = MV_TYPE_FIELD;\n s->mb_intra= 0;\n for(dir=0; dir<2; dir++){\n for(i=0; i<2; i++){\n j= s->field_select[dir][i] = s->b_field_select_table[dir][i][xy];\n s->mv[dir][i][0] = s->b_field_mv_table[dir][i][j][xy][0];\n s->mv[dir][i][1] = s->b_field_mv_table[dir][i][j][xy][1];\n }\n }\n encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BIDIR_I, pb, pb2, tex_pb,\n &dmin, &next_block, 0, 0);\n }\n if(mb_type&CANDIDATE_MB_TYPE_INTRA){\n s->mv_dir = 0;\n s->mv_type = MV_TYPE_16X16;\n s->mb_intra= 1;\n s->mv[0][0][0] = 0;\n s->mv[0][0][1] = 0;\n encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTRA, pb, pb2, tex_pb,\n &dmin, &next_block, 0, 0);\n if(s->h263_pred || s->h263_aic){\n if(best_s.mb_intra)\n s->mbintra_table[mb_x + mb_y*s->mb_stride]=1;\n else\n ff_clean_intra_table_entries(s);\n }\n }\n if ((s->mpv_flags & FF_MPV_FLAG_QP_RD) && dmin < INT_MAX) {\n if(best_s.mv_type==MV_TYPE_16X16){\n const int last_qp= backup_s.qscale;\n int qpi, qp, dc[6];\n int16_t ac[6][16];\n const int mvdir= (best_s.mv_dir&MV_DIR_BACKWARD) ? 1 : 0;\n static const int dquant_tab[4]={-1,1,-2,2};\n assert(backup_s.dquant == 0);\n s->mv_dir= best_s.mv_dir;\n s->mv_type = MV_TYPE_16X16;\n s->mb_intra= best_s.mb_intra;\n s->mv[0][0][0] = best_s.mv[0][0][0];\n s->mv[0][0][1] = best_s.mv[0][0][1];\n s->mv[1][0][0] = best_s.mv[1][0][0];\n s->mv[1][0][1] = best_s.mv[1][0][1];\n qpi = s->pict_type == AV_PICTURE_TYPE_B ? 2 : 0;\n for(; qpi<4; qpi++){\n int dquant= dquant_tab[qpi];\n qp= last_qp + dquant;\n if(qp < s->avctx->qmin || qp > s->avctx->qmax)\n continue;\n backup_s.dquant= dquant;\n if(s->mb_intra && s->dc_val[0]){\n for(i=0; i<6; i++){\n dc[i]= s->dc_val[0][ s->block_index[i] ];\n memcpy(ac[i], s->ac_val[0][s->block_index[i]], sizeof(int16_t)*16);\n }\n }\n encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER , pb, pb2, tex_pb,\n &dmin, &next_block, s->mv[mvdir][0][0], s->mv[mvdir][0][1]);\n if(best_s.qscale != qp){\n if(s->mb_intra && s->dc_val[0]){\n for(i=0; i<6; i++){\n s->dc_val[0][ s->block_index[i] ]= dc[i];\n memcpy(s->ac_val[0][s->block_index[i]], ac[i], sizeof(int16_t)*16);\n }\n }\n }\n }\n }\n }\n if(CONFIG_MPEG4_ENCODER && mb_type&CANDIDATE_MB_TYPE_DIRECT){\n int mx= s->b_direct_mv_table[xy][0];\n int my= s->b_direct_mv_table[xy][1];\n backup_s.dquant = 0;\n s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;\n s->mb_intra= 0;\n ff_mpeg4_set_direct_mv(s, mx, my);\n encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb,\n &dmin, &next_block, mx, my);\n }\n if(CONFIG_MPEG4_ENCODER && mb_type&CANDIDATE_MB_TYPE_DIRECT0){\n backup_s.dquant = 0;\n s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;\n s->mb_intra= 0;\n ff_mpeg4_set_direct_mv(s, 0, 0);\n encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb,\n &dmin, &next_block, 0, 0);\n }\n if (!best_s.mb_intra && s->mpv_flags & FF_MPV_FLAG_SKIP_RD) {\n int coded=0;\n for(i=0; i<6; i++)\n coded |= s->block_last_index[i];\n if(coded){\n int mx,my;\n memcpy(s->mv, best_s.mv, sizeof(s->mv));\n if(CONFIG_MPEG4_ENCODER && best_s.mv_dir & MV_DIRECT){\n mx=my=0;\n ff_mpeg4_set_direct_mv(s, mx, my);\n }else if(best_s.mv_dir&MV_DIR_BACKWARD){\n mx= s->mv[1][0][0];\n my= s->mv[1][0][1];\n }else{\n mx= s->mv[0][0][0];\n my= s->mv[0][0][1];\n }\n s->mv_dir= best_s.mv_dir;\n s->mv_type = best_s.mv_type;\n s->mb_intra= 0;\n backup_s.dquant= 0;\n s->skipdct=1;\n encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER , pb, pb2, tex_pb,\n &dmin, &next_block, mx, my);\n s->skipdct=0;\n }\n }\n s->current_picture.qscale_table[xy] = best_s.qscale;\n copy_context_after_encode(s, &best_s, -1);\n pb_bits_count= put_bits_count(&s->pb);\n flush_put_bits(&s->pb);\n avpriv_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count);\n s->pb= backup_s.pb;\n if(s->data_partitioning){\n pb2_bits_count= put_bits_count(&s->pb2);\n flush_put_bits(&s->pb2);\n avpriv_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count);\n s->pb2= backup_s.pb2;\n tex_pb_bits_count= put_bits_count(&s->tex_pb);\n flush_put_bits(&s->tex_pb);\n avpriv_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count);\n s->tex_pb= backup_s.tex_pb;\n }\n s->last_bits= put_bits_count(&s->pb);\n if (CONFIG_H263_ENCODER &&\n s->out_format == FMT_H263 && s->pict_type!=AV_PICTURE_TYPE_B)\n ff_h263_update_motion_val(s);\n if(next_block==0){\n s->hdsp.put_pixels_tab[0][0](s->dest[0], s->rd_scratchpad , s->linesize ,16);\n s->hdsp.put_pixels_tab[1][0](s->dest[1], s->rd_scratchpad + 16*s->linesize , s->uvlinesize, 8);\n s->hdsp.put_pixels_tab[1][0](s->dest[2], s->rd_scratchpad + 16*s->linesize + 8, s->uvlinesize, 8);\n }\n if(s->avctx->mb_decision == FF_MB_DECISION_BITS)\n ff_mpv_decode_mb(s, s->block);\n } else {\n int motion_x = 0, motion_y = 0;\n s->mv_type=MV_TYPE_16X16;\n switch(mb_type){\n case CANDIDATE_MB_TYPE_INTRA:\n s->mv_dir = 0;\n s->mb_intra= 1;\n motion_x= s->mv[0][0][0] = 0;\n motion_y= s->mv[0][0][1] = 0;\n break;\n case CANDIDATE_MB_TYPE_INTER:\n s->mv_dir = MV_DIR_FORWARD;\n s->mb_intra= 0;\n motion_x= s->mv[0][0][0] = s->p_mv_table[xy][0];\n motion_y= s->mv[0][0][1] = s->p_mv_table[xy][1];\n break;\n case CANDIDATE_MB_TYPE_INTER_I:\n s->mv_dir = MV_DIR_FORWARD;\n s->mv_type = MV_TYPE_FIELD;\n s->mb_intra= 0;\n for(i=0; i<2; i++){\n j= s->field_select[0][i] = s->p_field_select_table[i][xy];\n s->mv[0][i][0] = s->p_field_mv_table[i][j][xy][0];\n s->mv[0][i][1] = s->p_field_mv_table[i][j][xy][1];\n }\n break;\n case CANDIDATE_MB_TYPE_INTER4V:\n s->mv_dir = MV_DIR_FORWARD;\n s->mv_type = MV_TYPE_8X8;\n s->mb_intra= 0;\n for(i=0; i<4; i++){\n s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0];\n s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1];\n }\n break;\n case CANDIDATE_MB_TYPE_DIRECT:\n if (CONFIG_MPEG4_ENCODER) {\n s->mv_dir = MV_DIR_FORWARD|MV_DIR_BACKWARD|MV_DIRECT;\n s->mb_intra= 0;\n motion_x=s->b_direct_mv_table[xy][0];\n motion_y=s->b_direct_mv_table[xy][1];\n ff_mpeg4_set_direct_mv(s, motion_x, motion_y);\n }\n break;\n case CANDIDATE_MB_TYPE_DIRECT0:\n if (CONFIG_MPEG4_ENCODER) {\n s->mv_dir = MV_DIR_FORWARD|MV_DIR_BACKWARD|MV_DIRECT;\n s->mb_intra= 0;\n ff_mpeg4_set_direct_mv(s, 0, 0);\n }\n break;\n case CANDIDATE_MB_TYPE_BIDIR:\n s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;\n s->mb_intra= 0;\n s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0];\n s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1];\n s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0];\n s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1];\n break;\n case CANDIDATE_MB_TYPE_BACKWARD:\n s->mv_dir = MV_DIR_BACKWARD;\n s->mb_intra= 0;\n motion_x= s->mv[1][0][0] = s->b_back_mv_table[xy][0];\n motion_y= s->mv[1][0][1] = s->b_back_mv_table[xy][1];\n break;\n case CANDIDATE_MB_TYPE_FORWARD:\n s->mv_dir = MV_DIR_FORWARD;\n s->mb_intra= 0;\n motion_x= s->mv[0][0][0] = s->b_forw_mv_table[xy][0];\n motion_y= s->mv[0][0][1] = s->b_forw_mv_table[xy][1];\n break;\n case CANDIDATE_MB_TYPE_FORWARD_I:\n s->mv_dir = MV_DIR_FORWARD;\n s->mv_type = MV_TYPE_FIELD;\n s->mb_intra= 0;\n for(i=0; i<2; i++){\n j= s->field_select[0][i] = s->b_field_select_table[0][i][xy];\n s->mv[0][i][0] = s->b_field_mv_table[0][i][j][xy][0];\n s->mv[0][i][1] = s->b_field_mv_table[0][i][j][xy][1];\n }\n break;\n case CANDIDATE_MB_TYPE_BACKWARD_I:\n s->mv_dir = MV_DIR_BACKWARD;\n s->mv_type = MV_TYPE_FIELD;\n s->mb_intra= 0;\n for(i=0; i<2; i++){\n j= s->field_select[1][i] = s->b_field_select_table[1][i][xy];\n s->mv[1][i][0] = s->b_field_mv_table[1][i][j][xy][0];\n s->mv[1][i][1] = s->b_field_mv_table[1][i][j][xy][1];\n }\n break;\n case CANDIDATE_MB_TYPE_BIDIR_I:\n s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;\n s->mv_type = MV_TYPE_FIELD;\n s->mb_intra= 0;\n for(dir=0; dir<2; dir++){\n for(i=0; i<2; i++){\n j= s->field_select[dir][i] = s->b_field_select_table[dir][i][xy];\n s->mv[dir][i][0] = s->b_field_mv_table[dir][i][j][xy][0];\n s->mv[dir][i][1] = s->b_field_mv_table[dir][i][j][xy][1];\n }\n }\n break;\n default:\n av_log(s->avctx, AV_LOG_ERROR, "illegal MB type\\n");\n }\n encode_mb(s, motion_x, motion_y);\n s->last_mv_dir = s->mv_dir;\n if (CONFIG_H263_ENCODER &&\n s->out_format == FMT_H263 && s->pict_type!=AV_PICTURE_TYPE_B)\n ff_h263_update_motion_val(s);\n ff_mpv_decode_mb(s, s->block);\n }\n if(s->mb_intra ){\n s->p_mv_table[xy][0]=0;\n s->p_mv_table[xy][1]=0;\n }\n if(s->flags&CODEC_FLAG_PSNR){\n int w= 16;\n int h= 16;\n if(s->mb_x*16 + 16 > s->width ) w= s->width - s->mb_x*16;\n if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16;\n s->current_picture.f->error[0] += sse(\n s, s->new_picture.f->data[0] + s->mb_x*16 + s->mb_y*s->linesize*16,\n s->dest[0], w, h, s->linesize);\n s->current_picture.f->error[1] += sse(\n s, s->new_picture.f->data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*chr_h,\n s->dest[1], w>>1, h>>s->chroma_y_shift, s->uvlinesize);\n s->current_picture.f->error[2] += sse(\n s, s->new_picture.f->data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*chr_h,\n s->dest[2], w>>1, h>>s->chroma_y_shift, s->uvlinesize);\n }\n if(s->loop_filter){\n if(CONFIG_H263_ENCODER && s->out_format == FMT_H263)\n ff_h263_loop_filter(s);\n }\n av_dlog(s->avctx, "MB %d %d bits\\n",\n s->mb_x + s->mb_y * s->mb_stride, put_bits_count(&s->pb));\n }\n }\n if (CONFIG_MSMPEG4_ENCODER && s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type == AV_PICTURE_TYPE_I)\n ff_msmpeg4_encode_ext_header(s);\n write_slice_end(s);\n if (s->avctx->rtp_callback) {\n int number_mb = (mb_y - s->resync_mb_y)*s->mb_width - s->resync_mb_x;\n pdif = put_bits_ptr(&s->pb) - s->ptr_lastgob;\n emms_c();\n s->avctx->rtp_callback(s->avctx, s->ptr_lastgob, pdif, number_mb);\n }\n return 0;\n}']
34,869
0
https://github.com/openssl/openssl/blob/fbb7b33b28e3026c7443339c1f300ef725e2ff50/crypto/mem.c/#L281
void CRYPTO_free(void *str, const char *file, int line) { if (free_impl != NULL && free_impl != &CRYPTO_free) { free_impl(str, file, line); return; } #ifndef OPENSSL_NO_CRYPTO_MDEBUG if (call_malloc_debug) { CRYPTO_mem_debug_free(str, 0, file, line); free(str); CRYPTO_mem_debug_free(str, 1, file, line); } else { free(str); } #else free(str); #endif }
["static int ssl_ctx_make_profiles(const char *profiles_string,\n STACK_OF(SRTP_PROTECTION_PROFILE) **out)\n{\n STACK_OF(SRTP_PROTECTION_PROFILE) *profiles;\n char *col;\n char *ptr = (char *)profiles_string;\n SRTP_PROTECTION_PROFILE *p;\n if ((profiles = sk_SRTP_PROTECTION_PROFILE_new_null()) == NULL) {\n SSLerr(SSL_F_SSL_CTX_MAKE_PROFILES,\n SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES);\n return 1;\n }\n do {\n col = strchr(ptr, ':');\n if (!find_profile_by_name(ptr, &p, col ? (size_t)(col - ptr)\n : strlen(ptr))) {\n if (sk_SRTP_PROTECTION_PROFILE_find(profiles, p) >= 0) {\n SSLerr(SSL_F_SSL_CTX_MAKE_PROFILES,\n SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST);\n goto err;\n }\n if (!sk_SRTP_PROTECTION_PROFILE_push(profiles, p)) {\n SSLerr(SSL_F_SSL_CTX_MAKE_PROFILES,\n SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES);\n goto err;\n }\n } else {\n SSLerr(SSL_F_SSL_CTX_MAKE_PROFILES,\n SSL_R_SRTP_UNKNOWN_PROTECTION_PROFILE);\n goto err;\n }\n if (col)\n ptr = col + 1;\n } while (col);\n sk_SRTP_PROTECTION_PROFILE_free(*out);\n *out = profiles;\n return 0;\n err:\n sk_SRTP_PROTECTION_PROFILE_free(profiles);\n return 1;\n}", 'DEFINE_STACK_OF(SRTP_PROTECTION_PROFILE)', 'int OPENSSL_sk_push(OPENSSL_STACK *st, const void *data)\n{\n if (st == NULL)\n return -1;\n return OPENSSL_sk_insert(st, data, st->num);\n}', 'int OPENSSL_sk_insert(OPENSSL_STACK *st, const void *data, int loc)\n{\n if (st == NULL || st->num == max_nodes)\n return 0;\n if (!sk_reserve(st, 1, 0))\n return 0;\n if ((loc >= st->num) || (loc < 0)) {\n st->data[st->num] = data;\n } else {\n memmove(&st->data[loc + 1], &st->data[loc],\n sizeof(st->data[0]) * (st->num - loc));\n st->data[loc] = data;\n }\n st->num++;\n st->sorted = 0;\n return st->num;\n}', 'static int sk_reserve(OPENSSL_STACK *st, int n, int exact)\n{\n const void **tmpdata;\n int num_alloc;\n if (n > max_nodes - st->num)\n return 0;\n num_alloc = st->num + n;\n if (num_alloc < min_nodes)\n num_alloc = min_nodes;\n if (st->data == NULL) {\n st->data = OPENSSL_zalloc(sizeof(void *) * num_alloc);\n if (st->data == NULL)\n return 0;\n st->num_alloc = num_alloc;\n return 1;\n }\n if (!exact) {\n if (num_alloc <= st->num_alloc)\n return 1;\n num_alloc = compute_growth(num_alloc, st->num_alloc);\n if (num_alloc == 0)\n return 0;\n } else if (num_alloc == st->num_alloc) {\n return 1;\n }\n tmpdata = OPENSSL_realloc((void *)st->data, sizeof(void *) * num_alloc);\n if (tmpdata == NULL)\n return 0;\n st->data = tmpdata;\n st->num_alloc = num_alloc;\n return 1;\n}', 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n if (realloc_impl != NULL && realloc_impl != &CRYPTO_realloc)\n return realloc_impl(str, num, file, line);\n FAILTEST();\n if (str == NULL)\n return CRYPTO_malloc(num, file, line);\n if (num == 0) {\n CRYPTO_free(str, file, line);\n return NULL;\n }\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n void *ret;\n CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);\n ret = realloc(str, num);\n CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);\n return ret;\n }\n#else\n (void)(file); (void)(line);\n#endif\n return realloc(str, num);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
34,870
0
https://github.com/libav/libav/blob/555000c7d5c1e13043a948ebc48d2939b0ba6536/libavformat/utils.c/#L2631
void avformat_free_context(AVFormatContext *s) { int i; AVStream *st; av_opt_free(s); if (s->iformat && s->iformat->priv_class && s->priv_data) av_opt_free(s->priv_data); for(i=0;i<s->nb_streams;i++) { st = s->streams[i]; if (st->parser) { av_parser_close(st->parser); } if (st->attached_pic.data) av_free_packet(&st->attached_pic); av_dict_free(&st->metadata); av_free(st->index_entries); av_free(st->codec->extradata); av_free(st->codec->subtitle_header); av_free(st->codec); av_free(st->priv_data); av_free(st->info); av_free(st); } for(i=s->nb_programs-1; i>=0; i--) { av_dict_free(&s->programs[i]->metadata); av_freep(&s->programs[i]->stream_index); av_freep(&s->programs[i]); } av_freep(&s->programs); av_freep(&s->priv_data); while(s->nb_chapters--) { av_dict_free(&s->chapters[s->nb_chapters]->metadata); av_free(s->chapters[s->nb_chapters]); } av_freep(&s->chapters); av_dict_free(&s->metadata); av_freep(&s->streams); av_free(s); }
['int ff_wms_parse_sdp_a_line(AVFormatContext *s, const char *p)\n{\n int ret = 0;\n if (av_strstart(p, "pgmpu:data:application/vnd.ms.wms-hdr.asfv1;base64,", &p)) {\n AVIOContext pb;\n RTSPState *rt = s->priv_data;\n AVDictionary *opts = NULL;\n int len = strlen(p) * 6 / 8;\n char *buf = av_mallocz(len);\n av_base64_decode(buf, p, len);\n if (rtp_asf_fix_header(buf, len) < 0)\n av_log(s, AV_LOG_ERROR,\n "Failed to fix invalid RTSP-MS/ASF min_pktsize\\n");\n init_packetizer(&pb, buf, len);\n if (rt->asf_ctx) {\n avformat_close_input(&rt->asf_ctx);\n }\n if (!(rt->asf_ctx = avformat_alloc_context()))\n return AVERROR(ENOMEM);\n rt->asf_ctx->pb = &pb;\n av_dict_set(&opts, "no_resync_search", "1", 0);\n ret = avformat_open_input(&rt->asf_ctx, "", &ff_asf_demuxer, &opts);\n av_dict_free(&opts);\n if (ret < 0)\n return ret;\n av_dict_copy(&s->metadata, rt->asf_ctx->metadata, 0);\n rt->asf_pb_pos = avio_tell(&pb);\n av_free(buf);\n rt->asf_ctx->pb = NULL;\n }\n return ret;\n}', "int av_base64_decode(uint8_t *out, const char *in, int out_size)\n{\n int i;\n unsigned v = 0;\n uint8_t *dst = out;\n for (i = 0; in[i] && in[i] != '='; i++) {\n unsigned int index= in[i]-43;\n if (index>=FF_ARRAY_ELEMS(map2) || map2[index] == 0xff)\n return -1;\n v = (v << 6) + map2[index];\n if (i & 3) {\n if (dst - out < out_size) {\n *dst++ = v >> (6 - 2 * (i & 3));\n }\n }\n }\n return dst - out;\n}", 'static int rtp_asf_fix_header(uint8_t *buf, int len)\n{\n uint8_t *p = buf, *end = buf + len;\n if (len < sizeof(ff_asf_guid) * 2 + 22 ||\n memcmp(p, ff_asf_header, sizeof(ff_asf_guid))) {\n return -1;\n }\n p += sizeof(ff_asf_guid) + 14;\n do {\n uint64_t chunksize = AV_RL64(p + sizeof(ff_asf_guid));\n if (memcmp(p, ff_asf_file_header, sizeof(ff_asf_guid))) {\n if (chunksize > end - p)\n return -1;\n p += chunksize;\n continue;\n }\n p += 6 * 8 + 3 * 4 + sizeof(ff_asf_guid) * 2;\n if (p + 8 <= end && AV_RL32(p) == AV_RL32(p + 4)) {\n AV_WL32(p, 0);\n return 0;\n }\n break;\n } while (end - p >= sizeof(ff_asf_guid) + 8);\n return -1;\n}', 'void avformat_close_input(AVFormatContext **ps)\n{\n AVFormatContext *s = *ps;\n AVIOContext *pb = s->pb;\n if ((s->iformat && s->iformat->flags & AVFMT_NOFILE) ||\n (s->flags & AVFMT_FLAG_CUSTOM_IO))\n pb = NULL;\n flush_packet_queue(s);\n if (s->iformat) {\n if (s->iformat->read_close)\n s->iformat->read_close(s);\n }\n avformat_free_context(s);\n *ps = NULL;\n avio_close(pb);\n}', 'void avformat_free_context(AVFormatContext *s)\n{\n int i;\n AVStream *st;\n av_opt_free(s);\n if (s->iformat && s->iformat->priv_class && s->priv_data)\n av_opt_free(s->priv_data);\n for(i=0;i<s->nb_streams;i++) {\n st = s->streams[i];\n if (st->parser) {\n av_parser_close(st->parser);\n }\n if (st->attached_pic.data)\n av_free_packet(&st->attached_pic);\n av_dict_free(&st->metadata);\n av_free(st->index_entries);\n av_free(st->codec->extradata);\n av_free(st->codec->subtitle_header);\n av_free(st->codec);\n av_free(st->priv_data);\n av_free(st->info);\n av_free(st);\n }\n for(i=s->nb_programs-1; i>=0; i--) {\n av_dict_free(&s->programs[i]->metadata);\n av_freep(&s->programs[i]->stream_index);\n av_freep(&s->programs[i]);\n }\n av_freep(&s->programs);\n av_freep(&s->priv_data);\n while(s->nb_chapters--) {\n av_dict_free(&s->chapters[s->nb_chapters]->metadata);\n av_free(s->chapters[s->nb_chapters]);\n }\n av_freep(&s->chapters);\n av_dict_free(&s->metadata);\n av_freep(&s->streams);\n av_free(s);\n}']
34,871
0
https://github.com/libav/libav/blob/5bf2ac2b37ae17df7f2bd541801bec8c049b8d2c/libavformat/utils.c/#L2670
void avformat_free_context(AVFormatContext *s) { int i; AVStream *st; av_opt_free(s); if (s->iformat && s->iformat->priv_class && s->priv_data) av_opt_free(s->priv_data); for(i=0;i<s->nb_streams;i++) { st = s->streams[i]; if (st->parser) { av_parser_close(st->parser); av_free_packet(&st->cur_pkt); } av_dict_free(&st->metadata); av_free(st->index_entries); av_free(st->codec->extradata); av_free(st->codec->subtitle_header); av_free(st->codec); av_free(st->priv_data); av_free(st->info); av_free(st); } for(i=s->nb_programs-1; i>=0; i--) { av_dict_free(&s->programs[i]->metadata); av_freep(&s->programs[i]->stream_index); av_freep(&s->programs[i]); } av_freep(&s->programs); av_freep(&s->priv_data); while(s->nb_chapters--) { av_dict_free(&s->chapters[s->nb_chapters]->metadata); av_free(s->chapters[s->nb_chapters]); } av_freep(&s->chapters); av_dict_free(&s->metadata); av_freep(&s->streams); av_free(s); }
['int ff_wms_parse_sdp_a_line(AVFormatContext *s, const char *p)\n{\n int ret = 0;\n if (av_strstart(p, "pgmpu:data:application/vnd.ms.wms-hdr.asfv1;base64,", &p)) {\n AVIOContext pb;\n RTSPState *rt = s->priv_data;\n int len = strlen(p) * 6 / 8;\n char *buf = av_mallocz(len);\n av_base64_decode(buf, p, len);\n if (rtp_asf_fix_header(buf, len) < 0)\n av_log(s, AV_LOG_ERROR,\n "Failed to fix invalid RTSP-MS/ASF min_pktsize\\n");\n init_packetizer(&pb, buf, len);\n if (rt->asf_ctx) {\n avformat_close_input(&rt->asf_ctx);\n }\n if (!(rt->asf_ctx = avformat_alloc_context()))\n return AVERROR(ENOMEM);\n rt->asf_ctx->pb = &pb;\n ret = avformat_open_input(&rt->asf_ctx, "", &ff_asf_demuxer, NULL);\n if (ret < 0)\n return ret;\n av_dict_copy(&s->metadata, rt->asf_ctx->metadata, 0);\n rt->asf_pb_pos = avio_tell(&pb);\n av_free(buf);\n rt->asf_ctx->pb = NULL;\n }\n return ret;\n}', "int av_base64_decode(uint8_t *out, const char *in, int out_size)\n{\n int i, v;\n uint8_t *dst = out;\n v = 0;\n for (i = 0; in[i] && in[i] != '='; i++) {\n unsigned int index= in[i]-43;\n if (index>=FF_ARRAY_ELEMS(map2) || map2[index] == 0xff)\n return -1;\n v = (v << 6) + map2[index];\n if (i & 3) {\n if (dst - out < out_size) {\n *dst++ = v >> (6 - 2 * (i & 3));\n }\n }\n }\n return dst - out;\n}", 'static int rtp_asf_fix_header(uint8_t *buf, int len)\n{\n uint8_t *p = buf, *end = buf + len;\n if (len < sizeof(ff_asf_guid) * 2 + 22 ||\n memcmp(p, ff_asf_header, sizeof(ff_asf_guid))) {\n return -1;\n }\n p += sizeof(ff_asf_guid) + 14;\n do {\n uint64_t chunksize = AV_RL64(p + sizeof(ff_asf_guid));\n if (memcmp(p, ff_asf_file_header, sizeof(ff_asf_guid))) {\n if (chunksize > end - p)\n return -1;\n p += chunksize;\n continue;\n }\n p += 6 * 8 + 3 * 4 + sizeof(ff_asf_guid) * 2;\n if (p + 8 <= end && AV_RL32(p) == AV_RL32(p + 4)) {\n AV_WL32(p, 0);\n return 0;\n }\n break;\n } while (end - p >= sizeof(ff_asf_guid) + 8);\n return -1;\n}', 'void avformat_close_input(AVFormatContext **ps)\n{\n AVFormatContext *s = *ps;\n AVIOContext *pb = (s->iformat->flags & AVFMT_NOFILE) || (s->flags & AVFMT_FLAG_CUSTOM_IO) ?\n NULL : s->pb;\n flush_packet_queue(s);\n if (s->iformat->read_close)\n s->iformat->read_close(s);\n avformat_free_context(s);\n *ps = NULL;\n if (pb)\n avio_close(pb);\n}', 'void avformat_free_context(AVFormatContext *s)\n{\n int i;\n AVStream *st;\n av_opt_free(s);\n if (s->iformat && s->iformat->priv_class && s->priv_data)\n av_opt_free(s->priv_data);\n for(i=0;i<s->nb_streams;i++) {\n st = s->streams[i];\n if (st->parser) {\n av_parser_close(st->parser);\n av_free_packet(&st->cur_pkt);\n }\n av_dict_free(&st->metadata);\n av_free(st->index_entries);\n av_free(st->codec->extradata);\n av_free(st->codec->subtitle_header);\n av_free(st->codec);\n av_free(st->priv_data);\n av_free(st->info);\n av_free(st);\n }\n for(i=s->nb_programs-1; i>=0; i--) {\n av_dict_free(&s->programs[i]->metadata);\n av_freep(&s->programs[i]->stream_index);\n av_freep(&s->programs[i]);\n }\n av_freep(&s->programs);\n av_freep(&s->priv_data);\n while(s->nb_chapters--) {\n av_dict_free(&s->chapters[s->nb_chapters]->metadata);\n av_free(s->chapters[s->nb_chapters]);\n }\n av_freep(&s->chapters);\n av_dict_free(&s->metadata);\n av_freep(&s->streams);\n av_free(s);\n}']
34,872
0
https://github.com/libav/libav/blob/47399ccdfd93d337c96c76fbf591f0e3637131ef/libavcodec/bitstream.h/#L245
static inline void bitstream_skip(BitstreamContext *bc, unsigned n) { if (n < bc->bits_left) skip_remaining(bc, n); else { n -= bc->bits_left; bc->bits = 0; bc->bits_left = 0; if (n >= 64) { unsigned skip = n / 8; n -= skip * 8; bc->ptr += skip; } refill_64(bc); if (n) skip_remaining(bc, n); } }
['static int cavs_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,\n AVPacket *avpkt)\n{\n AVSContext *h = avctx->priv_data;\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n uint32_t stc = -1;\n int input_size, ret;\n const uint8_t *buf_end;\n const uint8_t *buf_ptr;\n if (buf_size == 0) {\n if (!h->low_delay && h->DPB[0].f->data[0]) {\n *got_frame = 1;\n av_frame_move_ref(data, h->DPB[0].f);\n }\n return 0;\n }\n buf_ptr = buf;\n buf_end = buf + buf_size;\n for(;;) {\n buf_ptr = avpriv_find_start_code(buf_ptr, buf_end, &stc);\n if ((stc & 0xFFFFFE00) || buf_ptr == buf_end)\n return FFMAX(0, buf_ptr - buf);\n input_size = (buf_end - buf_ptr) * 8;\n switch (stc) {\n case CAVS_START_CODE:\n bitstream_init(&h->bc, buf_ptr, input_size);\n decode_seq_header(h);\n break;\n case PIC_I_START_CODE:\n if (!h->got_keyframe) {\n av_frame_unref(h->DPB[0].f);\n av_frame_unref(h->DPB[1].f);\n h->got_keyframe = 1;\n }\n case PIC_PB_START_CODE:\n *got_frame = 0;\n if (!h->got_keyframe)\n break;\n bitstream_init(&h->bc, buf_ptr, input_size);\n h->stc = stc;\n if (decode_pic(h))\n break;\n *got_frame = 1;\n if (h->cur.f->pict_type != AV_PICTURE_TYPE_B) {\n if (h->DPB[1].f->data[0]) {\n if ((ret = av_frame_ref(data, h->DPB[1].f)) < 0)\n return ret;\n } else {\n *got_frame = 0;\n }\n } else {\n av_frame_move_ref(data, h->cur.f);\n }\n break;\n case EXT_START_CODE:\n break;\n case USER_START_CODE:\n break;\n default:\n if (stc <= SLICE_MAX_START_CODE) {\n bitstream_init(&h->bc, buf_ptr, input_size);\n decode_slice_header(h, &h->bc);\n }\n break;\n }\n }\n}', 'static inline int bitstream_init(BitstreamContext *bc, const uint8_t *buffer,\n unsigned bit_size)\n{\n unsigned buffer_size;\n if (bit_size > INT_MAX - 7 || !buffer) {\n buffer =\n bc->buffer =\n bc->ptr = NULL;\n bc->bits_left = 0;\n return AVERROR_INVALIDDATA;\n }\n buffer_size = (bit_size + 7) >> 3;\n bc->buffer = buffer;\n bc->buffer_end = buffer + buffer_size;\n bc->ptr = bc->buffer;\n bc->size_in_bits = bit_size;\n bc->bits_left = 0;\n bc->bits = 0;\n refill_64(bc);\n return 0;\n}', 'static int decode_pic(AVSContext *h)\n{\n int ret;\n int skip_count = -1;\n enum cavs_mb mb_type;\n if (!h->top_qp) {\n av_log(h->avctx, AV_LOG_ERROR, "No sequence header decoded yet\\n");\n return AVERROR_INVALIDDATA;\n }\n av_frame_unref(h->cur.f);\n bitstream_skip(&h->bc, 16);\n if (h->stc == PIC_PB_START_CODE) {\n h->cur.f->pict_type = bitstream_read(&h->bc, 2) + AV_PICTURE_TYPE_I;\n if (h->cur.f->pict_type > AV_PICTURE_TYPE_B) {\n av_log(h->avctx, AV_LOG_ERROR, "illegal picture type\\n");\n return AVERROR_INVALIDDATA;\n }\n if (!h->DPB[0].f->data[0] ||\n (!h->DPB[1].f->data[0] && h->cur.f->pict_type == AV_PICTURE_TYPE_B))\n return AVERROR_INVALIDDATA;\n } else {\n h->cur.f->pict_type = AV_PICTURE_TYPE_I;\n if (bitstream_read_bit(&h->bc))\n bitstream_skip(&h->bc, 24);\n if (h->low_delay || !(bitstream_peek(&h->bc, 9) & 1))\n h->stream_revision = 1;\n else if (bitstream_peek(&h->bc, 11) & 3)\n h->stream_revision = 1;\n if (h->stream_revision > 0)\n bitstream_skip(&h->bc, 1);\n }\n ret = ff_get_buffer(h->avctx, h->cur.f, h->cur.f->pict_type == AV_PICTURE_TYPE_B ?\n 0 : AV_GET_BUFFER_FLAG_REF);\n if (ret < 0)\n return ret;\n if (!h->edge_emu_buffer) {\n int alloc_size = FFALIGN(FFABS(h->cur.f->linesize[0]) + 32, 32);\n h->edge_emu_buffer = av_mallocz(alloc_size * 2 * 24);\n if (!h->edge_emu_buffer)\n return AVERROR(ENOMEM);\n }\n ff_cavs_init_pic(h);\n h->cur.poc = bitstream_read(&h->bc, 8) * 2;\n if (h->cur.f->pict_type != AV_PICTURE_TYPE_B) {\n h->dist[0] = (h->cur.poc - h->DPB[0].poc + 512) % 512;\n } else {\n h->dist[0] = (h->DPB[0].poc - h->cur.poc + 512) % 512;\n }\n h->dist[1] = (h->cur.poc - h->DPB[1].poc + 512) % 512;\n h->scale_den[0] = h->dist[0] ? 512/h->dist[0] : 0;\n h->scale_den[1] = h->dist[1] ? 512/h->dist[1] : 0;\n if (h->cur.f->pict_type == AV_PICTURE_TYPE_B) {\n h->sym_factor = h->dist[0] * h->scale_den[1];\n } else {\n h->direct_den[0] = h->dist[0] ? 16384 / h->dist[0] : 0;\n h->direct_den[1] = h->dist[1] ? 16384 / h->dist[1] : 0;\n }\n if (h->low_delay)\n get_ue_golomb(&h->bc);\n h->progressive = bitstream_read_bit(&h->bc);\n h->pic_structure = 1;\n if (!h->progressive)\n h->pic_structure = bitstream_read_bit(&h->bc);\n if (!h->pic_structure && h->stc == PIC_PB_START_CODE)\n bitstream_skip(&h->bc, 1);\n bitstream_skip(&h->bc, 1);\n bitstream_skip(&h->bc, 1);\n h->qp_fixed = bitstream_read_bit(&h->bc);\n h->qp = bitstream_read(&h->bc, 6);\n if (h->cur.f->pict_type == AV_PICTURE_TYPE_I) {\n if (!h->progressive && !h->pic_structure)\n bitstream_skip(&h->bc, 1);\n bitstream_skip(&h->bc, 4);\n } else {\n if (!(h->cur.f->pict_type == AV_PICTURE_TYPE_B && h->pic_structure == 1))\n h->ref_flag = bitstream_read_bit(&h->bc);\n bitstream_skip(&h->bc, 4);\n h->skip_mode_flag = bitstream_read_bit(&h->bc);\n }\n h->loop_filter_disable = bitstream_read_bit(&h->bc);\n if (!h->loop_filter_disable && bitstream_read_bit(&h->bc)) {\n h->alpha_offset = get_se_golomb(&h->bc);\n h->beta_offset = get_se_golomb(&h->bc);\n } else {\n h->alpha_offset = h->beta_offset = 0;\n }\n if (h->cur.f->pict_type == AV_PICTURE_TYPE_I) {\n do {\n check_for_slice(h);\n decode_mb_i(h, 0);\n } while (ff_cavs_next_mb(h));\n } else if (h->cur.f->pict_type == AV_PICTURE_TYPE_P) {\n do {\n if (check_for_slice(h))\n skip_count = -1;\n if (h->skip_mode_flag && (skip_count < 0))\n skip_count = get_ue_golomb(&h->bc);\n if (h->skip_mode_flag && skip_count--) {\n decode_mb_p(h, P_SKIP);\n } else {\n mb_type = get_ue_golomb(&h->bc) + P_SKIP + h->skip_mode_flag;\n if (mb_type > P_8X8)\n decode_mb_i(h, mb_type - P_8X8 - 1);\n else\n decode_mb_p(h, mb_type);\n }\n } while (ff_cavs_next_mb(h));\n } else {\n do {\n if (check_for_slice(h))\n skip_count = -1;\n if (h->skip_mode_flag && (skip_count < 0))\n skip_count = get_ue_golomb(&h->bc);\n if (h->skip_mode_flag && skip_count--) {\n decode_mb_b(h, B_SKIP);\n } else {\n mb_type = get_ue_golomb(&h->bc) + B_SKIP + h->skip_mode_flag;\n if (mb_type > B_8X8)\n decode_mb_i(h, mb_type - B_8X8 - 1);\n else\n decode_mb_b(h, mb_type);\n }\n } while (ff_cavs_next_mb(h));\n }\n if (h->cur.f->pict_type != AV_PICTURE_TYPE_B) {\n av_frame_unref(h->DPB[1].f);\n FFSWAP(AVSFrame, h->cur, h->DPB[1]);\n FFSWAP(AVSFrame, h->DPB[0], h->DPB[1]);\n }\n return 0;\n}', 'static inline void bitstream_skip(BitstreamContext *bc, unsigned n)\n{\n if (n < bc->bits_left)\n skip_remaining(bc, n);\n else {\n n -= bc->bits_left;\n bc->bits = 0;\n bc->bits_left = 0;\n if (n >= 64) {\n unsigned skip = n / 8;\n n -= skip * 8;\n bc->ptr += skip;\n }\n refill_64(bc);\n if (n)\n skip_remaining(bc, n);\n }\n}']
34,873
0
https://github.com/libav/libav/blob/452a398fd6bdca3f301c5c8af3bc241bc16a777e/libavformat/nsvdec.c/#L324
static int nsv_parse_NSVf_header(AVFormatContext *s, AVFormatParameters *ap) { NSVContext *nsv = s->priv_data; ByteIOContext *pb = s->pb; unsigned int file_size, size; int64_t duration; int strings_size; int table_entries; int table_entries_used; PRINT(("%s()\n", __FUNCTION__)); nsv->state = NSV_UNSYNC; size = get_le32(pb); if (size < 28) return -1; nsv->NSVf_end = size; file_size = (uint32_t)get_le32(pb); PRINT(("NSV NSVf chunk_size %u\n", size)); PRINT(("NSV NSVf file_size %u\n", file_size)); nsv->duration = duration = get_le32(pb); PRINT(("NSV NSVf duration %"PRId64" ms\n", duration)); strings_size = get_le32(pb); table_entries = get_le32(pb); table_entries_used = get_le32(pb); PRINT(("NSV NSVf info-strings size: %d, table entries: %d, bis %d\n", strings_size, table_entries, table_entries_used)); if (url_feof(pb)) return -1; PRINT(("NSV got header; filepos %"PRId64"\n", url_ftell(pb))); if (strings_size > 0) { char *strings; char *p, *endp; char *token, *value; char quote; p = strings = av_mallocz(strings_size + 1); endp = strings + strings_size; get_buffer(pb, strings, strings_size); while (p < endp) { while (*p == ' ') p++; if (p >= endp-2) break; token = p; p = strchr(p, '='); if (!p || p >= endp-2) break; *p++ = '\0'; quote = *p++; value = p; p = strchr(p, quote); if (!p || p >= endp) break; *p++ = '\0'; PRINT(("NSV NSVf INFO: %s='%s'\n", token, value)); if (!strcmp(token, "ASPECT")) { } else if (!strcmp(token, "CREATOR") || !strcmp(token, "Author")) { strncpy(s->author, value, 512-1); } else if (!strcmp(token, "Copyright")) { strncpy(s->copyright, value, 512-1); } else if (!strcmp(token, "TITLE") || !strcmp(token, "Title")) { strncpy(s->title, value, 512-1); } } av_free(strings); } if (url_feof(pb)) return -1; PRINT(("NSV got infos; filepos %"PRId64"\n", url_ftell(pb))); if (table_entries_used > 0) { nsv->index_entries = table_entries_used; if((unsigned)table_entries >= UINT_MAX / sizeof(uint32_t)) return -1; nsv->nsvf_index_data = av_malloc(table_entries * sizeof(uint32_t)); #warning "FIXME: Byteswap buffer as needed" get_buffer(pb, (unsigned char *)nsv->nsvf_index_data, table_entries * sizeof(uint32_t)); } PRINT(("NSV got index; filepos %"PRId64"\n", url_ftell(pb))); #ifdef DEBUG_DUMP_INDEX #define V(v) ((v<0x20 || v > 127)?'.':v) PRINT(("NSV %d INDEX ENTRIES:\n", table_entries)); PRINT(("NSV [dataoffset][fileoffset]\n", table_entries)); for (i = 0; i < table_entries; i++) { unsigned char b[8]; url_fseek(pb, size + nsv->nsvf_index_data[i], SEEK_SET); get_buffer(pb, b, 8); PRINT(("NSV [0x%08lx][0x%08lx]: %02x %02x %02x %02x %02x %02x %02x %02x" "%c%c%c%c%c%c%c%c\n", nsv->nsvf_index_data[i], size + nsv->nsvf_index_data[i], b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], V(b[0]), V(b[1]), V(b[2]), V(b[3]), V(b[4]), V(b[5]), V(b[6]), V(b[7]) )); } #undef V #endif url_fseek(pb, nsv->base_offset + size, SEEK_SET); if (url_feof(pb)) return -1; nsv->state = NSV_HAS_READ_NSVF; return 0; }
['static int nsv_parse_NSVf_header(AVFormatContext *s, AVFormatParameters *ap)\n{\n NSVContext *nsv = s->priv_data;\n ByteIOContext *pb = s->pb;\n unsigned int file_size, size;\n int64_t duration;\n int strings_size;\n int table_entries;\n int table_entries_used;\n PRINT(("%s()\\n", __FUNCTION__));\n nsv->state = NSV_UNSYNC;\n size = get_le32(pb);\n if (size < 28)\n return -1;\n nsv->NSVf_end = size;\n file_size = (uint32_t)get_le32(pb);\n PRINT(("NSV NSVf chunk_size %u\\n", size));\n PRINT(("NSV NSVf file_size %u\\n", file_size));\n nsv->duration = duration = get_le32(pb);\n PRINT(("NSV NSVf duration %"PRId64" ms\\n", duration));\n strings_size = get_le32(pb);\n table_entries = get_le32(pb);\n table_entries_used = get_le32(pb);\n PRINT(("NSV NSVf info-strings size: %d, table entries: %d, bis %d\\n",\n strings_size, table_entries, table_entries_used));\n if (url_feof(pb))\n return -1;\n PRINT(("NSV got header; filepos %"PRId64"\\n", url_ftell(pb)));\n if (strings_size > 0) {\n char *strings;\n char *p, *endp;\n char *token, *value;\n char quote;\n p = strings = av_mallocz(strings_size + 1);\n endp = strings + strings_size;\n get_buffer(pb, strings, strings_size);\n while (p < endp) {\n while (*p == \' \')\n p++;\n if (p >= endp-2)\n break;\n token = p;\n p = strchr(p, \'=\');\n if (!p || p >= endp-2)\n break;\n *p++ = \'\\0\';\n quote = *p++;\n value = p;\n p = strchr(p, quote);\n if (!p || p >= endp)\n break;\n *p++ = \'\\0\';\n PRINT(("NSV NSVf INFO: %s=\'%s\'\\n", token, value));\n if (!strcmp(token, "ASPECT")) {\n } else if (!strcmp(token, "CREATOR") || !strcmp(token, "Author")) {\n strncpy(s->author, value, 512-1);\n } else if (!strcmp(token, "Copyright")) {\n strncpy(s->copyright, value, 512-1);\n } else if (!strcmp(token, "TITLE") || !strcmp(token, "Title")) {\n strncpy(s->title, value, 512-1);\n }\n }\n av_free(strings);\n }\n if (url_feof(pb))\n return -1;\n PRINT(("NSV got infos; filepos %"PRId64"\\n", url_ftell(pb)));\n if (table_entries_used > 0) {\n nsv->index_entries = table_entries_used;\n if((unsigned)table_entries >= UINT_MAX / sizeof(uint32_t))\n return -1;\n nsv->nsvf_index_data = av_malloc(table_entries * sizeof(uint32_t));\n#warning "FIXME: Byteswap buffer as needed"\n get_buffer(pb, (unsigned char *)nsv->nsvf_index_data, table_entries * sizeof(uint32_t));\n }\n PRINT(("NSV got index; filepos %"PRId64"\\n", url_ftell(pb)));\n#ifdef DEBUG_DUMP_INDEX\n#define V(v) ((v<0x20 || v > 127)?\'.\':v)\n PRINT(("NSV %d INDEX ENTRIES:\\n", table_entries));\n PRINT(("NSV [dataoffset][fileoffset]\\n", table_entries));\n for (i = 0; i < table_entries; i++) {\n unsigned char b[8];\n url_fseek(pb, size + nsv->nsvf_index_data[i], SEEK_SET);\n get_buffer(pb, b, 8);\n PRINT(("NSV [0x%08lx][0x%08lx]: %02x %02x %02x %02x %02x %02x %02x %02x"\n "%c%c%c%c%c%c%c%c\\n",\n nsv->nsvf_index_data[i], size + nsv->nsvf_index_data[i],\n b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7],\n V(b[0]), V(b[1]), V(b[2]), V(b[3]), V(b[4]), V(b[5]), V(b[6]), V(b[7]) ));\n }\n#undef V\n#endif\n url_fseek(pb, nsv->base_offset + size, SEEK_SET);\n if (url_feof(pb))\n return -1;\n nsv->state = NSV_HAS_READ_NSVF;\n return 0;\n}', 'unsigned int get_le32(ByteIOContext *s)\n{\n unsigned int val;\n val = get_le16(s);\n val |= get_le16(s) << 16;\n return val;\n}', 'unsigned int get_le16(ByteIOContext *s)\n{\n unsigned int val;\n val = get_byte(s);\n val |= get_byte(s) << 8;\n return val;\n}', 'int get_byte(ByteIOContext *s)\n{\n if (s->buf_ptr < s->buf_end) {\n return *s->buf_ptr++;\n } else {\n fill_buffer(s);\n if (s->buf_ptr < s->buf_end)\n return *s->buf_ptr++;\n else\n return 0;\n }\n}', 'int url_feof(ByteIOContext *s)\n{\n if(!s)\n return 0;\n return s->eof_reached;\n}', 'void *av_mallocz(unsigned int size)\n{\n void *ptr = av_malloc(size);\n if (ptr)\n memset(ptr, 0, size);\n return ptr;\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr;\n#ifdef CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#ifdef CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif defined (HAVE_MEMALIGN)\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
34,874
0
https://github.com/libav/libav/blob/4f0b80599a534dcca57be3184b89b98f82bf2a2c/libavformat/nsvdec.c/#L314
static int nsv_parse_NSVf_header(AVFormatContext *s, AVFormatParameters *ap) { NSVContext *nsv = s->priv_data; AVIOContext *pb = s->pb; unsigned int file_size, size; int64_t duration; int strings_size; int table_entries; int table_entries_used; av_dlog(s, "%s()\n", __FUNCTION__); nsv->state = NSV_UNSYNC; size = avio_rl32(pb); if (size < 28) return -1; nsv->NSVf_end = size; file_size = (uint32_t)avio_rl32(pb); av_dlog(s, "NSV NSVf chunk_size %u\n", size); av_dlog(s, "NSV NSVf file_size %u\n", file_size); nsv->duration = duration = avio_rl32(pb); av_dlog(s, "NSV NSVf duration %"PRId64" ms\n", duration); strings_size = avio_rl32(pb); table_entries = avio_rl32(pb); table_entries_used = avio_rl32(pb); av_dlog(s, "NSV NSVf info-strings size: %d, table entries: %d, bis %d\n", strings_size, table_entries, table_entries_used); if (pb->eof_reached) return -1; av_dlog(s, "NSV got header; filepos %"PRId64"\n", avio_tell(pb)); if (strings_size > 0) { char *strings; char *p, *endp; char *token, *value; char quote; p = strings = av_mallocz(strings_size + 1); endp = strings + strings_size; avio_read(pb, strings, strings_size); while (p < endp) { while (*p == ' ') p++; if (p >= endp-2) break; token = p; p = strchr(p, '='); if (!p || p >= endp-2) break; *p++ = '\0'; quote = *p++; value = p; p = strchr(p, quote); if (!p || p >= endp) break; *p++ = '\0'; av_dlog(s, "NSV NSVf INFO: %s='%s'\n", token, value); av_metadata_set2(&s->metadata, token, value, 0); } av_free(strings); } if (pb->eof_reached) return -1; av_dlog(s, "NSV got infos; filepos %"PRId64"\n", avio_tell(pb)); if (table_entries_used > 0) { int i; nsv->index_entries = table_entries_used; if((unsigned)table_entries_used >= UINT_MAX / sizeof(uint32_t)) return -1; nsv->nsvs_file_offset = av_malloc((unsigned)table_entries_used * sizeof(uint32_t)); for(i=0;i<table_entries_used;i++) nsv->nsvs_file_offset[i] = avio_rl32(pb) + size; if(table_entries > table_entries_used && avio_rl32(pb) == MKTAG('T','O','C','2')) { nsv->nsvs_timestamps = av_malloc((unsigned)table_entries_used*sizeof(uint32_t)); for(i=0;i<table_entries_used;i++) { nsv->nsvs_timestamps[i] = avio_rl32(pb); } } } av_dlog(s, "NSV got index; filepos %"PRId64"\n", avio_tell(pb)); #ifdef DEBUG_DUMP_INDEX #define V(v) ((v<0x20 || v > 127)?'.':v) av_dlog(s, "NSV %d INDEX ENTRIES:\n", table_entries); av_dlog(s, "NSV [dataoffset][fileoffset]\n", table_entries); for (i = 0; i < table_entries; i++) { unsigned char b[8]; avio_seek(pb, size + nsv->nsvs_file_offset[i], SEEK_SET); avio_read(pb, b, 8); av_dlog(s, "NSV [0x%08lx][0x%08lx]: %02x %02x %02x %02x %02x %02x %02x %02x" "%c%c%c%c%c%c%c%c\n", nsv->nsvs_file_offset[i], size + nsv->nsvs_file_offset[i], b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], V(b[0]), V(b[1]), V(b[2]), V(b[3]), V(b[4]), V(b[5]), V(b[6]), V(b[7]) ); } #undef V #endif avio_seek(pb, nsv->base_offset + size, SEEK_SET); if (pb->eof_reached) return -1; nsv->state = NSV_HAS_READ_NSVF; return 0; }
['static int nsv_parse_NSVf_header(AVFormatContext *s, AVFormatParameters *ap)\n{\n NSVContext *nsv = s->priv_data;\n AVIOContext *pb = s->pb;\n unsigned int file_size, size;\n int64_t duration;\n int strings_size;\n int table_entries;\n int table_entries_used;\n av_dlog(s, "%s()\\n", __FUNCTION__);\n nsv->state = NSV_UNSYNC;\n size = avio_rl32(pb);\n if (size < 28)\n return -1;\n nsv->NSVf_end = size;\n file_size = (uint32_t)avio_rl32(pb);\n av_dlog(s, "NSV NSVf chunk_size %u\\n", size);\n av_dlog(s, "NSV NSVf file_size %u\\n", file_size);\n nsv->duration = duration = avio_rl32(pb);\n av_dlog(s, "NSV NSVf duration %"PRId64" ms\\n", duration);\n strings_size = avio_rl32(pb);\n table_entries = avio_rl32(pb);\n table_entries_used = avio_rl32(pb);\n av_dlog(s, "NSV NSVf info-strings size: %d, table entries: %d, bis %d\\n",\n strings_size, table_entries, table_entries_used);\n if (pb->eof_reached)\n return -1;\n av_dlog(s, "NSV got header; filepos %"PRId64"\\n", avio_tell(pb));\n if (strings_size > 0) {\n char *strings;\n char *p, *endp;\n char *token, *value;\n char quote;\n p = strings = av_mallocz(strings_size + 1);\n endp = strings + strings_size;\n avio_read(pb, strings, strings_size);\n while (p < endp) {\n while (*p == \' \')\n p++;\n if (p >= endp-2)\n break;\n token = p;\n p = strchr(p, \'=\');\n if (!p || p >= endp-2)\n break;\n *p++ = \'\\0\';\n quote = *p++;\n value = p;\n p = strchr(p, quote);\n if (!p || p >= endp)\n break;\n *p++ = \'\\0\';\n av_dlog(s, "NSV NSVf INFO: %s=\'%s\'\\n", token, value);\n av_metadata_set2(&s->metadata, token, value, 0);\n }\n av_free(strings);\n }\n if (pb->eof_reached)\n return -1;\n av_dlog(s, "NSV got infos; filepos %"PRId64"\\n", avio_tell(pb));\n if (table_entries_used > 0) {\n int i;\n nsv->index_entries = table_entries_used;\n if((unsigned)table_entries_used >= UINT_MAX / sizeof(uint32_t))\n return -1;\n nsv->nsvs_file_offset = av_malloc((unsigned)table_entries_used * sizeof(uint32_t));\n for(i=0;i<table_entries_used;i++)\n nsv->nsvs_file_offset[i] = avio_rl32(pb) + size;\n if(table_entries > table_entries_used &&\n avio_rl32(pb) == MKTAG(\'T\',\'O\',\'C\',\'2\')) {\n nsv->nsvs_timestamps = av_malloc((unsigned)table_entries_used*sizeof(uint32_t));\n for(i=0;i<table_entries_used;i++) {\n nsv->nsvs_timestamps[i] = avio_rl32(pb);\n }\n }\n }\n av_dlog(s, "NSV got index; filepos %"PRId64"\\n", avio_tell(pb));\n#ifdef DEBUG_DUMP_INDEX\n#define V(v) ((v<0x20 || v > 127)?\'.\':v)\n av_dlog(s, "NSV %d INDEX ENTRIES:\\n", table_entries);\n av_dlog(s, "NSV [dataoffset][fileoffset]\\n", table_entries);\n for (i = 0; i < table_entries; i++) {\n unsigned char b[8];\n avio_seek(pb, size + nsv->nsvs_file_offset[i], SEEK_SET);\n avio_read(pb, b, 8);\n av_dlog(s, "NSV [0x%08lx][0x%08lx]: %02x %02x %02x %02x %02x %02x %02x %02x"\n "%c%c%c%c%c%c%c%c\\n",\n nsv->nsvs_file_offset[i], size + nsv->nsvs_file_offset[i],\n b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7],\n V(b[0]), V(b[1]), V(b[2]), V(b[3]), V(b[4]), V(b[5]), V(b[6]), V(b[7]) );\n }\n#undef V\n#endif\n avio_seek(pb, nsv->base_offset + size, SEEK_SET);\n if (pb->eof_reached)\n return -1;\n nsv->state = NSV_HAS_READ_NSVF;\n return 0;\n}', 'unsigned int avio_rl32(AVIOContext *s)\n{\n unsigned int val;\n val = avio_rl16(s);\n val |= avio_rl16(s) << 16;\n return val;\n}', 'unsigned int avio_rl16(AVIOContext *s)\n{\n unsigned int val;\n val = avio_r8(s);\n val |= avio_r8(s) << 8;\n return val;\n}', 'int avio_r8(AVIOContext *s)\n{\n if (s->buf_ptr >= s->buf_end)\n fill_buffer(s);\n if (s->buf_ptr < s->buf_end)\n return *s->buf_ptr++;\n return 0;\n}', 'void *av_mallocz(size_t size)\n{\n void *ptr = av_malloc(size);\n if (ptr)\n memset(ptr, 0, size);\n return ptr;\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-32) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+32);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&31) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,32,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(32,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
34,875
0
https://github.com/libav/libav/blob/7fce481a69053dd24dbf9f1cb0f5b51df2ec925c/libavfilter/avfilter.c/#L59
void avfilter_unref_buffer(AVFilterBufferRef *ref) { if(!(--ref->buf->refcount)) ref->buf->free(ref->buf); av_free(ref); }
['static int request_frame(AVFilterLink *link)\n{\n BufferSourceContext *c = link->src->priv;\n AVFilterBufferRef *picref;\n if (!c->has_frame) {\n av_log(link->src, AV_LOG_ERROR,\n "request_frame() called with no available frame!\\n");\n }\n picref = avfilter_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE |\n AV_PERM_REUSE2,\n link->w, link->h);\n av_picture_copy((AVPicture *)&picref->data, (AVPicture *)&c->frame,\n picref->format, link->w, link->h);\n picref->pts = c->pts;\n picref->pixel_aspect = c->pixel_aspect;\n picref->interlaced = c->frame.interlaced_frame;\n picref->top_field_first = c->frame.top_field_first;\n avfilter_start_frame(link, avfilter_ref_buffer(picref, ~0));\n avfilter_draw_slice(link, 0, link->h, 1);\n avfilter_end_frame(link);\n avfilter_unref_buffer(picref);\n c->has_frame = 0;\n return 0;\n}', 'void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)\n{\n uint8_t *src[4], *dst[4];\n int i, j, vsub;\n void (*draw_slice)(AVFilterLink *, int, int, int);\n FF_DPRINTF_START(NULL, draw_slice); ff_dprintf_link(NULL, link, 0); dprintf(NULL, " y:%d h:%d dir:%d\\n", y, h, slice_dir);\n if(link->srcpic) {\n vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h;\n for(i = 0; i < 4; i ++) {\n if(link->srcpic->data[i]) {\n src[i] = link->srcpic-> data[i] +\n (y >> (i==0 ? 0 : vsub)) * link->srcpic-> linesize[i];\n dst[i] = link->cur_pic->data[i] +\n (y >> (i==0 ? 0 : vsub)) * link->cur_pic->linesize[i];\n } else\n src[i] = dst[i] = NULL;\n }\n for(i = 0; i < 4; i ++) {\n int planew =\n ff_get_plane_bytewidth(link->format, link->cur_pic->w, i);\n if(!src[i]) continue;\n for(j = 0; j < h >> (i==0 ? 0 : vsub); j ++) {\n memcpy(dst[i], src[i], planew);\n src[i] += link->srcpic ->linesize[i];\n dst[i] += link->cur_pic->linesize[i];\n }\n }\n }\n if(!(draw_slice = link_dpad(link).draw_slice))\n draw_slice = avfilter_default_draw_slice;\n draw_slice(link, y, h, slice_dir);\n}', 'void avfilter_unref_buffer(AVFilterBufferRef *ref)\n{\n if(!(--ref->buf->refcount))\n ref->buf->free(ref->buf);\n av_free(ref);\n}']
34,876
0
https://github.com/openssl/openssl/blob/f9df0a7775f483c175cda5832360cccd1db6943a/crypto/bn/bn_lib.c/#L271
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words) { BN_ULONG *a = NULL; bn_check_top(b); if (words > (INT_MAX / (4 * BN_BITS2))) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG); return NULL; } if (BN_get_flags(b, BN_FLG_STATIC_DATA)) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); return (NULL); } if (BN_get_flags(b, BN_FLG_SECURE)) a = OPENSSL_secure_zalloc(words * sizeof(*a)); else a = OPENSSL_zalloc(words * sizeof(*a)); if (a == NULL) { BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE); return (NULL); } assert(b->top <= words); if (b->top > 0) memcpy(a, b->d, sizeof(*a) * b->top); return a; }
['BIGNUM *int_bn_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx,\n int *pnoinv)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n if (pnoinv)\n *pnoinv = 0;\n if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0)) {\n return BN_mod_inverse_no_branch(in, a, n, ctx);\n }\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n if (!BN_nnmod(B, B, A, ctx))\n goto err;\n }\n sign = -1;\n if (BN_is_odd(n) && (BN_num_bits(n) <= 2048)) {\n int shift;\n while (!BN_is_zero(B)) {\n shift = 0;\n while (!BN_is_bit_set(B, shift)) {\n shift++;\n if (BN_is_odd(X)) {\n if (!BN_uadd(X, X, n))\n goto err;\n }\n if (!BN_rshift1(X, X))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(B, B, shift))\n goto err;\n }\n shift = 0;\n while (!BN_is_bit_set(A, shift)) {\n shift++;\n if (BN_is_odd(Y)) {\n if (!BN_uadd(Y, Y, n))\n goto err;\n }\n if (!BN_rshift1(Y, Y))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(A, A, shift))\n goto err;\n }\n if (BN_ucmp(B, A) >= 0) {\n if (!BN_uadd(X, X, Y))\n goto err;\n if (!BN_usub(B, B, A))\n goto err;\n } else {\n if (!BN_uadd(Y, Y, X))\n goto err;\n if (!BN_usub(A, A, B))\n goto err;\n }\n }\n } else {\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n if (BN_num_bits(A) == BN_num_bits(B)) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else if (BN_num_bits(A) == BN_num_bits(B) + 1) {\n if (!BN_lshift1(T, B))\n goto err;\n if (BN_ucmp(A, T) < 0) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else {\n if (!BN_sub(M, A, T))\n goto err;\n if (!BN_add(D, T, B))\n goto err;\n if (BN_ucmp(A, D) < 0) {\n if (!BN_set_word(D, 2))\n goto err;\n } else {\n if (!BN_set_word(D, 3))\n goto err;\n if (!BN_sub(M, M, B))\n goto err;\n }\n }\n } else {\n if (!BN_div(D, M, A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (BN_is_one(D)) {\n if (!BN_add(tmp, X, Y))\n goto err;\n } else {\n if (BN_is_word(D, 2)) {\n if (!BN_lshift1(tmp, X))\n goto err;\n } else if (BN_is_word(D, 4)) {\n if (!BN_lshift(tmp, X, 2))\n goto err;\n } else if (D->top == 1) {\n if (!BN_copy(tmp, X))\n goto err;\n if (!BN_mul_word(tmp, D->d[0]))\n goto err;\n } else {\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n }\n if (!BN_add(tmp, tmp, Y))\n goto err;\n }\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n if (pnoinv)\n *pnoinv = 1;\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return (ret);\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return 1;\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n bn_check_top(b);\n if (a == b)\n return a;\n if (bn_wexpand(a, b->top) == NULL)\n return NULL;\n if (b->top > 0)\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n if (BN_get_flags(b, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(a, BN_FLG_CONSTTIME);\n a->top = b->top;\n a->neg = b->neg;\n bn_check_top(a);\n return a;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}']
34,877
0
https://github.com/openssl/openssl/blob/84c15db551ce1d167b901a3bde2b21880b084384/crypto/bn/bn_lib.c/#L469
BIGNUM *bn_expand2(BIGNUM *b, int words) { BN_ULONG *A,*a; const BN_ULONG *B; int i; bn_check_top(b); if (words > b->max) { bn_check_top(b); if (BN_get_flags(b,BN_FLG_STATIC_DATA)) { BNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); return(NULL); } a=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1)); if (A == NULL) { BNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE); return(NULL); } #if 1 B=b->d; if (B != NULL) { #if 0 for (i=b->top&(~7); i>0; i-=8) { A[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3]; A[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7]; A+=8; B+=8; } switch (b->top&7) { case 7: A[6]=B[6]; case 6: A[5]=B[5]; case 5: A[4]=B[4]; case 4: A[3]=B[3]; case 3: A[2]=B[2]; case 2: A[1]=B[1]; case 1: A[0]=B[0]; case 0: ; } #else for (i=b->top>>2; i>0; i--,A+=4,B+=4) { BN_ULONG a0,a1,a2,a3; a0=B[0]; a1=B[1]; a2=B[2]; a3=B[3]; A[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3; } switch (b->top&3) { case 3: A[2]=B[2]; case 2: A[1]=B[1]; case 1: A[0]=B[0]; case 0: ; } #endif Free(b->d); } b->d=a; b->max=words; A= &(b->d[b->top]); for (i=(b->max - b->top)>>3; i>0; i--,A+=8) { A[0]=0; A[1]=0; A[2]=0; A[3]=0; A[4]=0; A[5]=0; A[6]=0; A[7]=0; } for (i=(b->max - b->top)&7; i>0; i--,A++) A[0]=0; #else memset(A,0,sizeof(BN_ULONG)*(words+1)); memcpy(A,b->d,sizeof(b->d[0])*b->top); b->d=a; b->max=words; #endif } return(b); }
['int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tBIGNUM Ri,*R;\n\tBN_init(&Ri);\n\tR= &(mont->RR);\n\tBN_copy(&(mont->N),mod);\n#ifdef BN_RECURSION_MONT\n\tif (mont->N.top < BN_MONT_CTX_SET_SIZE_WORD)\n#endif\n\t\t{\n\t\tBIGNUM tmod;\n\t\tBN_ULONG buf[2];\n\t\tmont->use_word=1;\n\t\tmont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;\n\t\tBN_zero(R);\n\t\tBN_set_bit(R,BN_BITS2);\n\t\tbuf[0]=mod->d[0];\n\t\tbuf[1]=0;\n\t\ttmod.d=buf;\n\t\ttmod.top=1;\n\t\ttmod.max=mod->max;\n\t\ttmod.neg=mod->neg;\n\t\tif ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tBN_lshift(&Ri,&Ri,BN_BITS2);\n\t\tif (!BN_is_zero(&Ri))\n\t\t\t{\n#if 1\n\t\t\tBN_sub_word(&Ri,1);\n#else\n\t\t\tBN_usub(&Ri,&Ri,BN_value_one());\n#endif\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tBN_set_word(&Ri,BN_MASK2);\n\t\t\t}\n\t\tBN_div(&Ri,NULL,&Ri,&tmod,ctx);\n\t\tmont->n0=Ri.d[0];\n\t\tBN_free(&Ri);\n\t\t}\n#ifdef BN_RECURSION_MONT\n\telse\n\t\t{\n\t\tmont->use_word=0;\n\t\tmont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;\n#if 1\n\t\tBN_zero(R);\n\t\tBN_set_bit(R,mont->ri);\n#else\n\t\tBN_lshift(R,BN_value_one(),mont->ri);\n#endif\n\t\tif ((BN_mod_inverse(&Ri,R,mod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tBN_lshift(&Ri,&Ri,mont->ri);\n#if 1\n\t\tBN_sub_word(&Ri,1);\n#else\n\t\tBN_usub(&Ri,&Ri,BN_value_one());\n#endif\n\t\tBN_div(&(mont->Ni),NULL,&Ri,mod,ctx);\n\t\tBN_free(&Ri);\n\t\t}\n#endif\n#if 1\n\tBN_zero(&(mont->RR));\n\tBN_set_bit(&(mont->RR),mont->ri*2);\n#else\n\tBN_lshift(mont->RR,BN_value_one(),mont->ri*2);\n#endif\n\tBN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx);\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n\t{\n\tint i,n;\n\tif (bn_expand(a,sizeof(BN_ULONG)*8) == NULL) return(0);\n\tn=sizeof(BN_ULONG)/BN_BYTES;\n\ta->neg=0;\n\ta->top=0;\n\ta->d[0]=(BN_ULONG)w&BN_MASK2;\n\tif (a->d[0] != 0) a->top=1;\n\tfor (i=1; i<n; i++)\n\t\t{\n#ifndef SIXTY_FOUR_BIT\n\t\tw>>=BN_BITS4;\n\t\tw>>=BN_BITS4;\n#else\n\t\tw=0;\n#endif\n\t\ta->d[i]=(BN_ULONG)w&BN_MASK2;\n\t\tif (a->d[i] != 0) a->top=i+1;\n\t\t}\n\treturn(1);\n\t}', 'int BN_set_bit(BIGNUM *a, int n)\n\t{\n\tint i,j,k;\n\ti=n/BN_BITS2;\n\tj=n%BN_BITS2;\n\tif (a->top <= i)\n\t\t{\n\t\tif (bn_wexpand(a,i+1) == NULL) return(0);\n\t\tfor(k=a->top; k<i+1; k++)\n\t\t\ta->d[k]=0;\n\t\ta->top=i+1;\n\t\t}\n\ta->d[i]|=(((BN_ULONG)1)<<j);\n\treturn(1);\n\t}', 'BIGNUM *BN_mod_inverse(BIGNUM *in, BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n\t{\n\tBIGNUM *A,*B,*X,*Y,*M,*D,*R;\n\tBIGNUM *T,*ret=NULL;\n\tint sign;\n\tbn_check_top(a);\n\tbn_check_top(n);\n\tA= &(ctx->bn[ctx->tos]);\n\tB= &(ctx->bn[ctx->tos+1]);\n\tX= &(ctx->bn[ctx->tos+2]);\n\tD= &(ctx->bn[ctx->tos+3]);\n\tM= &(ctx->bn[ctx->tos+4]);\n\tY= &(ctx->bn[ctx->tos+5]);\n\tctx->tos+=6;\n\tif (in == NULL)\n\t\tR=BN_new();\n\telse\n\t\tR=in;\n\tif (R == NULL) goto err;\n\tBN_zero(X);\n\tBN_one(Y);\n\tif (BN_copy(A,a) == NULL) goto err;\n\tif (BN_copy(B,n) == NULL) goto err;\n\tsign=1;\n\twhile (!BN_is_zero(B))\n\t\t{\n\t\tif (!BN_div(D,M,A,B,ctx)) goto err;\n\t\tT=A;\n\t\tA=B;\n\t\tB=M;\n\t\tif (!BN_mul(T,D,X,ctx)) goto err;\n\t\tif (!BN_add(T,T,Y)) goto err;\n\t\tM=Y;\n\t\tY=X;\n\t\tX=T;\n\t\tsign= -sign;\n\t\t}\n\tif (sign < 0)\n\t\t{\n\t\tif (!BN_sub(Y,n,Y)) goto err;\n\t\t}\n\tif (BN_is_one(A))\n\t\t{ if (!BN_mod(R,Y,n,ctx)) goto err; }\n\telse\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE);\n\t\tgoto err;\n\t\t}\n\tret=R;\nerr:\n\tif ((ret == NULL) && (in == NULL)) BN_free(R);\n\tctx->tos-=6;\n\treturn(ret);\n\t}', 'int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n\t{\n#if 0\n\tint i,nm,nd;\n\tBIGNUM *dv;\n\tif (BN_ucmp(m,d) < 0)\n\t\treturn((BN_copy(rem,m) == NULL)?0:1);\n\tdv= &(ctx->bn[ctx->tos]);\n\tif (!BN_copy(rem,m)) return(0);\n\tnm=BN_num_bits(rem);\n\tnd=BN_num_bits(d);\n\tif (!BN_lshift(dv,d,nm-nd)) return(0);\n\tfor (i=nm-nd; i>=0; i--)\n\t\t{\n\t\tif (BN_cmp(rem,dv) >= 0)\n\t\t\t{\n\t\t\tif (!BN_sub(rem,rem,dv)) return(0);\n\t\t\t}\n\t\tif (!BN_rshift1(dv,dv)) return(0);\n\t\t}\n\treturn(1);\n#else\n\treturn(BN_div(NULL,rem,m,d,ctx));\n#endif\n\t}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,j,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\ttmp= &(ctx->bn[ctx->tos]);\n\ttmp->neg=0;\n\tsnum= &(ctx->bn[ctx->tos+1]);\n\tsdiv= &(ctx->bn[ctx->tos+2]);\n\tif (dv == NULL)\n\t\tres= &(ctx->bn[ctx->tos+3]);\n\telse\tres=dv;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tBN_lshift(sdiv,divisor,norm_shift);\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tBN_lshift(snum,num,norm_shift);\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\tBN_init(&wnum);\n\twnum.d=\t &(snum->d[loop]);\n\twnum.top= div_n;\n\twnum.max= snum->max+1;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tif (!BN_usub(&wnum,&wnum,sdiv)) goto err;\n\t\t*resp=1;\n\t\tres->d[res->top-1]=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tresp--;\n\tfor (i=0; i<loop-1; i++)\n\t\t{\n\t\tBN_ULONG q,n0,n1;\n\t\tBN_ULONG l0;\n\t\twnum.d--; wnum.top++;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\tq=bn_div_words(n0,n1,d0);\n\t\t{\n#ifdef BN_LLONG\n\t\tBN_ULLONG t1,t2,rem;\n\t\tt1=((BN_ULLONG)n0<<BN_BITS2)|n1;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\trem=t1-(BN_ULLONG)q*d0;\n\t\t\tif ((rem>>BN_BITS2) ||\n\t\t\t\t(t2 <= ((BN_ULLONG)(rem<<BN_BITS2)+wnump[-2])))\n\t\t\t\tbreak;\n\t\t\tq--;\n\t\t\t}\n#else\n\t\tBN_ULONG t1l,t1h,t2l,t2h,t3l,t3h,ql,qh,t3t;\n\t\tt1h=n0;\n\t\tt1l=n1;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n\t\t\tt3t=LBITS(d0); t3h=HBITS(d0);\n\t\t\tmul64(t3t,t3h,ql,qh);\n\t\t\tt3l=(t1l-t3t)&BN_MASK2;\n\t\t\tif (t3l > t1l) t3h++;\n\t\t\tt3h=(t1h-t3h)&BN_MASK2;\n\t\t\tif (t3h) break;\n\t\t\tif (t2h < t3l) break;\n\t\t\tif ((t2h == t3l) && (t2l <= wnump[-2])) break;\n\t\t\tq--;\n\t\t\t}\n#endif\n\t\t}\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\tfor (j=div_n+1; j>0; j--)\n\t\t\tif (tmp->d[j-1]) break;\n\t\ttmp->top=j;\n\t\tj=wnum.top;\n\t\tBN_sub(&wnum,&wnum,tmp);\n\t\tsnum->top=snum->top+wnum.top-j;\n\t\tif (wnum.neg)\n\t\t\t{\n\t\t\tq--;\n\t\t\tj=wnum.top;\n\t\t\tBN_add(&wnum,&wnum,sdiv);\n\t\t\tsnum->top+=wnum.top-j;\n\t\t\t}\n\t\t*(resp--)=q;\n\t\twnump--;\n\t\t}\n\tif (rm != NULL)\n\t\t{\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\trm->neg=num->neg;\n\t\t}\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n\t{\n\tint i;\n\tBN_ULONG *A;\n\tconst BN_ULONG *B;\n\tbn_check_top(b);\n\tif (a == b) return(a);\n\tif (bn_wexpand(a,b->top) == NULL) return(NULL);\n#if 1\n\tA=a->d;\n\tB=b->d;\n\tfor (i=b->top>>2; i>0; i--,A+=4,B+=4)\n\t\t{\n\t\tBN_ULONG a0,a1,a2,a3;\n\t\ta0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];\n\t\tA[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;\n\t\t}\n\tswitch (b->top&3)\n\t\t{\n\t\tcase 3: A[2]=B[2];\n\t\tcase 2: A[1]=B[1];\n\t\tcase 1: A[0]=B[0];\n\t\tcase 0: ;\n\t\t}\n#else\n\tmemcpy(a->d,b->d,sizeof(b->d[0])*b->top);\n#endif\n\ta->top=b->top;\n\tif ((a->top == 0) && (a->d != NULL))\n\t\ta->d[0]=0;\n\ta->neg=b->neg;\n\treturn(a);\n\t}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n\t{\n\tBN_ULONG *A,*a;\n\tconst BN_ULONG *B;\n\tint i;\n\tbn_check_top(b);\n\tif (words > b->max)\n\t\t{\n\t\tbn_check_top(b);\n\t\tif (BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\ta=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1));\n\t\tif (A == NULL)\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE);\n\t\t\treturn(NULL);\n\t\t\t}\n#if 1\n\t\tB=b->d;\n\t\tif (B != NULL)\n\t\t\t{\n#if 0\n\t\t\tfor (i=b->top&(~7); i>0; i-=8)\n\t\t\t\t{\n\t\t\t\tA[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3];\n\t\t\t\tA[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7];\n\t\t\t\tA+=8;\n\t\t\t\tB+=8;\n\t\t\t\t}\n\t\t\tswitch (b->top&7)\n\t\t\t\t{\n\t\t\tcase 7:\n\t\t\t\tA[6]=B[6];\n\t\t\tcase 6:\n\t\t\t\tA[5]=B[5];\n\t\t\tcase 5:\n\t\t\t\tA[4]=B[4];\n\t\t\tcase 4:\n\t\t\t\tA[3]=B[3];\n\t\t\tcase 3:\n\t\t\t\tA[2]=B[2];\n\t\t\tcase 2:\n\t\t\t\tA[1]=B[1];\n\t\t\tcase 1:\n\t\t\t\tA[0]=B[0];\n\t\t\tcase 0:\n\t\t\t\t;\n\t\t\t\t}\n#else\n\t\t\tfor (i=b->top>>2; i>0; i--,A+=4,B+=4)\n\t\t\t\t{\n\t\t\t\tBN_ULONG a0,a1,a2,a3;\n\t\t\t\ta0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];\n\t\t\t\tA[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;\n\t\t\t\t}\n\t\t\tswitch (b->top&3)\n\t\t\t\t{\n\t\t\t\tcase 3:\tA[2]=B[2];\n\t\t\t\tcase 2:\tA[1]=B[1];\n\t\t\t\tcase 1:\tA[0]=B[0];\n\t\t\t\tcase 0:\t;\n\t\t\t\t}\n#endif\n\t\t\tFree(b->d);\n\t\t\t}\n\t\tb->d=a;\n\t\tb->max=words;\n\t\tA= &(b->d[b->top]);\n\t\tfor (i=(b->max - b->top)>>3; i>0; i--,A+=8)\n\t\t\t{\n\t\t\tA[0]=0; A[1]=0; A[2]=0; A[3]=0;\n\t\t\tA[4]=0; A[5]=0; A[6]=0; A[7]=0;\n\t\t\t}\n\t\tfor (i=(b->max - b->top)&7; i>0; i--,A++)\n\t\t\tA[0]=0;\n#else\n\t\t\tmemset(A,0,sizeof(BN_ULONG)*(words+1));\n\t\t\tmemcpy(A,b->d,sizeof(b->d[0])*b->top);\n\t\t\tb->d=a;\n\t\t\tb->max=words;\n#endif\n\t\t}\n\treturn(b);\n\t}']
34,878
0
https://github.com/openssl/openssl/blob/5d1c09de1f2736e1d4b1877206d08455ec75f558/include/internal/constant_time_locl.h/#L166
static ossl_inline unsigned int constant_time_is_zero(unsigned int a) { return constant_time_msb(~a & (a - 1)); }
['static int rsa_ossl_private_decrypt(int flen, const unsigned char *from,\n unsigned char *to, RSA *rsa, int padding)\n{\n BIGNUM *f, *ret;\n int j, num = 0, r = -1;\n unsigned char *buf = NULL;\n BN_CTX *ctx = NULL;\n int local_blinding = 0;\n BIGNUM *unblind = NULL;\n BN_BLINDING *blinding = NULL;\n if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n BN_CTX_start(ctx);\n f = BN_CTX_get(ctx);\n ret = BN_CTX_get(ctx);\n num = BN_num_bytes(rsa->n);\n buf = OPENSSL_malloc(num);\n if (ret == NULL || buf == NULL) {\n RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (flen > num) {\n RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT,\n RSA_R_DATA_GREATER_THAN_MOD_LEN);\n goto err;\n }\n if (BN_bin2bn(from, (int)flen, f) == NULL)\n goto err;\n if (BN_ucmp(f, rsa->n) >= 0) {\n RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT,\n RSA_R_DATA_TOO_LARGE_FOR_MODULUS);\n goto err;\n }\n if (!(rsa->flags & RSA_FLAG_NO_BLINDING)) {\n blinding = rsa_get_blinding(rsa, &local_blinding, ctx);\n if (blinding == NULL) {\n RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n }\n if (blinding != NULL) {\n if (!local_blinding && ((unblind = BN_CTX_get(ctx)) == NULL)) {\n RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (!rsa_blinding_convert(blinding, f, unblind, ctx))\n goto err;\n }\n if ((rsa->flags & RSA_FLAG_EXT_PKEY) ||\n (rsa->version == RSA_ASN1_VERSION_MULTI) ||\n ((rsa->p != NULL) &&\n (rsa->q != NULL) &&\n (rsa->dmp1 != NULL) && (rsa->dmq1 != NULL) && (rsa->iqmp != NULL))) {\n if (!rsa->meth->rsa_mod_exp(ret, f, rsa, ctx))\n goto err;\n } else {\n BIGNUM *d = BN_new();\n if (d == NULL) {\n RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);\n if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)\n if (!BN_MONT_CTX_set_locked\n (&rsa->_method_mod_n, rsa->lock, rsa->n, ctx)) {\n BN_free(d);\n goto err;\n }\n if (!rsa->meth->bn_mod_exp(ret, f, d, rsa->n, ctx,\n rsa->_method_mod_n)) {\n BN_free(d);\n goto err;\n }\n BN_free(d);\n }\n if (blinding)\n if (!rsa_blinding_invert(blinding, ret, unblind, ctx))\n goto err;\n j = BN_bn2binpad(ret, buf, num);\n switch (padding) {\n case RSA_PKCS1_PADDING:\n r = RSA_padding_check_PKCS1_type_2(to, num, buf, j, num);\n break;\n case RSA_PKCS1_OAEP_PADDING:\n r = RSA_padding_check_PKCS1_OAEP(to, num, buf, j, num, NULL, 0);\n break;\n case RSA_SSLV23_PADDING:\n r = RSA_padding_check_SSLv23(to, num, buf, j, num);\n break;\n case RSA_NO_PADDING:\n memcpy(to, buf, (r = j));\n break;\n default:\n RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, RSA_R_UNKNOWN_PADDING_TYPE);\n goto err;\n }\n if (r < 0)\n RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, RSA_R_PADDING_CHECK_FAILED);\n err:\n if (ctx != NULL)\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n OPENSSL_clear_free(buf, num);\n return r;\n}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n{\n unsigned int i, m;\n unsigned int n;\n BN_ULONG l;\n BIGNUM *bn = NULL;\n if (ret == NULL)\n ret = bn = BN_new();\n if (ret == NULL)\n return NULL;\n bn_check_top(ret);\n for ( ; len > 0 && *s == 0; s++, len--)\n continue;\n n = len;\n if (n == 0) {\n ret->top = 0;\n return ret;\n }\n i = ((n - 1) / BN_BYTES) + 1;\n m = ((n - 1) % (BN_BYTES));\n if (bn_wexpand(ret, (int)i) == NULL) {\n BN_free(bn);\n return NULL;\n }\n ret->top = i;\n ret->neg = 0;\n l = 0;\n while (n--) {\n l = (l << 8L) | *(s++);\n if (m-- == 0) {\n ret->d[--i] = l;\n l = 0;\n m = BN_BYTES - 1;\n }\n }\n bn_correct_top(ret);\n return ret;\n}', 'int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,\n const unsigned char *from, int flen,\n int num)\n{\n int i;\n unsigned char *em = NULL;\n unsigned int good, found_zero_byte;\n int zero_index = 0, msg_index, mlen = -1;\n if (tlen < 0 || flen < 0)\n return -1;\n if (flen > num)\n goto err;\n if (num < 11)\n goto err;\n if (flen != num) {\n em = OPENSSL_zalloc(num);\n if (em == NULL) {\n RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2, ERR_R_MALLOC_FAILURE);\n return -1;\n }\n memcpy(em + num - flen, from, flen);\n from = em;\n }\n good = constant_time_is_zero(from[0]);\n good &= constant_time_eq(from[1], 2);\n found_zero_byte = 0;\n for (i = 2; i < num; i++) {\n unsigned int equals0 = constant_time_is_zero(from[i]);\n zero_index =\n constant_time_select_int(~found_zero_byte & equals0, i,\n zero_index);\n found_zero_byte |= equals0;\n }\n good &= constant_time_ge((unsigned int)(zero_index), 2 + 8);\n msg_index = zero_index + 1;\n mlen = num - msg_index;\n good &= constant_time_ge((unsigned int)(tlen), (unsigned int)(mlen));\n if (!good) {\n mlen = -1;\n goto err;\n }\n memcpy(to, from + msg_index, mlen);\n err:\n OPENSSL_clear_free(em, num);\n if (mlen == -1)\n RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,\n RSA_R_PKCS_DECODING_ERROR);\n return mlen;\n}', 'static ossl_inline unsigned int constant_time_is_zero(unsigned int a)\n{\n return constant_time_msb(~a & (a - 1));\n}']
34,879
0
https://github.com/libav/libav/blob/baf35bb4bc4fe7a2a4113c50989d11dd9ef81e76/libavcodec/vc1dec.c/#L2811
static int vc1_decode_i_block_adv(VC1Context *v, int16_t block[64], int n, int coded, int codingset, int mquant) { GetBitContext *gb = &v->s.gb; MpegEncContext *s = &v->s; int dc_pred_dir = 0; int i; int16_t *dc_val; int16_t *ac_val, *ac_val2; int dcdiff; int a_avail = v->a_avail, c_avail = v->c_avail; int use_pred = s->ac_pred; int scale; int q1, q2 = 0; int mb_pos = s->mb_x + s->mb_y * s->mb_stride; if (n < 4) { dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3); } else { dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3); } if (dcdiff < 0) { av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n"); return -1; } if (dcdiff) { if (dcdiff == 119 ) { if (mquant == 1) dcdiff = get_bits(gb, 10); else if (mquant == 2) dcdiff = get_bits(gb, 9); else dcdiff = get_bits(gb, 8); } else { if (mquant == 1) dcdiff = (dcdiff << 2) + get_bits(gb, 2) - 3; else if (mquant == 2) dcdiff = (dcdiff << 1) + get_bits1(gb) - 1; } if (get_bits1(gb)) dcdiff = -dcdiff; } dcdiff += vc1_pred_dc(&v->s, v->overlap, mquant, n, v->a_avail, v->c_avail, &dc_val, &dc_pred_dir); *dc_val = dcdiff; if (n < 4) { block[0] = dcdiff * s->y_dc_scale; } else { block[0] = dcdiff * s->c_dc_scale; } i = 1; if (!a_avail && !c_avail) use_pred = 0; ac_val = s->ac_val[0][0] + s->block_index[n] * 16; ac_val2 = ac_val; scale = mquant * 2 + ((mquant == v->pq) ? v->halfpq : 0); if (dc_pred_dir) ac_val -= 16; else ac_val -= 16 * s->block_wrap[n]; q1 = s->current_picture.f.qscale_table[mb_pos]; if ( dc_pred_dir && c_avail && mb_pos) q2 = s->current_picture.f.qscale_table[mb_pos - 1]; if (!dc_pred_dir && a_avail && mb_pos >= s->mb_stride) q2 = s->current_picture.f.qscale_table[mb_pos - s->mb_stride]; if ( dc_pred_dir && n == 1) q2 = q1; if (!dc_pred_dir && n == 2) q2 = q1; if (n == 3) q2 = q1; if (coded) { int last = 0, skip, value; const uint8_t *zz_table; int k; if (v->s.ac_pred) { if (!use_pred && v->fcm == ILACE_FRAME) { zz_table = v->zzi_8x8; } else { if (!dc_pred_dir) zz_table = v->zz_8x8[2]; else zz_table = v->zz_8x8[3]; } } else { if (v->fcm != ILACE_FRAME) zz_table = v->zz_8x8[1]; else zz_table = v->zzi_8x8; } while (!last) { vc1_decode_ac_coeff(v, &last, &skip, &value, codingset); i += skip; if (i > 63) break; block[zz_table[i++]] = value; } if (use_pred) { if (q2 && q1 != q2) { q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1; q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1; if (q1 < 1) return AVERROR_INVALIDDATA; if (dc_pred_dir) { for (k = 1; k < 8; k++) block[k << v->left_blk_sh] += (ac_val[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; } else { for (k = 1; k < 8; k++) block[k << v->top_blk_sh] += (ac_val[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; } } else { if (dc_pred_dir) { for (k = 1; k < 8; k++) block[k << v->left_blk_sh] += ac_val[k]; } else { for (k = 1; k < 8; k++) block[k << v->top_blk_sh] += ac_val[k + 8]; } } } for (k = 1; k < 8; k++) { ac_val2[k ] = block[k << v->left_blk_sh]; ac_val2[k + 8] = block[k << v->top_blk_sh]; } for (k = 1; k < 64; k++) if (block[k]) { block[k] *= scale; if (!v->pquantizer) block[k] += (block[k] < 0) ? -mquant : mquant; } if (use_pred) i = 63; } else { int k; memset(ac_val2, 0, 16 * 2); if (dc_pred_dir) { if (use_pred) { memcpy(ac_val2, ac_val, 8 * 2); if (q2 && q1 != q2) { q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1; q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1; if (q1 < 1) return AVERROR_INVALIDDATA; for (k = 1; k < 8; k++) ac_val2[k] = (ac_val2[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; } } } else { if (use_pred) { memcpy(ac_val2 + 8, ac_val + 8, 8 * 2); if (q2 && q1 != q2) { q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1; q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1; if (q1 < 1) return AVERROR_INVALIDDATA; for (k = 1; k < 8; k++) ac_val2[k + 8] = (ac_val2[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; } } } if (use_pred) { if (dc_pred_dir) { for (k = 1; k < 8; k++) { block[k << v->left_blk_sh] = ac_val2[k] * scale; if (!v->pquantizer && block[k << v->left_blk_sh]) block[k << v->left_blk_sh] += (block[k << v->left_blk_sh] < 0) ? -mquant : mquant; } } else { for (k = 1; k < 8; k++) { block[k << v->top_blk_sh] = ac_val2[k + 8] * scale; if (!v->pquantizer && block[k << v->top_blk_sh]) block[k << v->top_blk_sh] += (block[k << v->top_blk_sh] < 0) ? -mquant : mquant; } } i = 63; } } s->block_last_index[n] = i; return 0; }
['static int vc1_decode_i_block_adv(VC1Context *v, int16_t block[64], int n,\n int coded, int codingset, int mquant)\n{\n GetBitContext *gb = &v->s.gb;\n MpegEncContext *s = &v->s;\n int dc_pred_dir = 0;\n int i;\n int16_t *dc_val;\n int16_t *ac_val, *ac_val2;\n int dcdiff;\n int a_avail = v->a_avail, c_avail = v->c_avail;\n int use_pred = s->ac_pred;\n int scale;\n int q1, q2 = 0;\n int mb_pos = s->mb_x + s->mb_y * s->mb_stride;\n if (n < 4) {\n dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);\n } else {\n dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);\n }\n if (dcdiff < 0) {\n av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\\n");\n return -1;\n }\n if (dcdiff) {\n if (dcdiff == 119 ) {\n if (mquant == 1) dcdiff = get_bits(gb, 10);\n else if (mquant == 2) dcdiff = get_bits(gb, 9);\n else dcdiff = get_bits(gb, 8);\n } else {\n if (mquant == 1)\n dcdiff = (dcdiff << 2) + get_bits(gb, 2) - 3;\n else if (mquant == 2)\n dcdiff = (dcdiff << 1) + get_bits1(gb) - 1;\n }\n if (get_bits1(gb))\n dcdiff = -dcdiff;\n }\n dcdiff += vc1_pred_dc(&v->s, v->overlap, mquant, n, v->a_avail, v->c_avail, &dc_val, &dc_pred_dir);\n *dc_val = dcdiff;\n if (n < 4) {\n block[0] = dcdiff * s->y_dc_scale;\n } else {\n block[0] = dcdiff * s->c_dc_scale;\n }\n i = 1;\n if (!a_avail && !c_avail)\n use_pred = 0;\n ac_val = s->ac_val[0][0] + s->block_index[n] * 16;\n ac_val2 = ac_val;\n scale = mquant * 2 + ((mquant == v->pq) ? v->halfpq : 0);\n if (dc_pred_dir)\n ac_val -= 16;\n else\n ac_val -= 16 * s->block_wrap[n];\n q1 = s->current_picture.f.qscale_table[mb_pos];\n if ( dc_pred_dir && c_avail && mb_pos)\n q2 = s->current_picture.f.qscale_table[mb_pos - 1];\n if (!dc_pred_dir && a_avail && mb_pos >= s->mb_stride)\n q2 = s->current_picture.f.qscale_table[mb_pos - s->mb_stride];\n if ( dc_pred_dir && n == 1)\n q2 = q1;\n if (!dc_pred_dir && n == 2)\n q2 = q1;\n if (n == 3)\n q2 = q1;\n if (coded) {\n int last = 0, skip, value;\n const uint8_t *zz_table;\n int k;\n if (v->s.ac_pred) {\n if (!use_pred && v->fcm == ILACE_FRAME) {\n zz_table = v->zzi_8x8;\n } else {\n if (!dc_pred_dir)\n zz_table = v->zz_8x8[2];\n else\n zz_table = v->zz_8x8[3];\n }\n } else {\n if (v->fcm != ILACE_FRAME)\n zz_table = v->zz_8x8[1];\n else\n zz_table = v->zzi_8x8;\n }\n while (!last) {\n vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);\n i += skip;\n if (i > 63)\n break;\n block[zz_table[i++]] = value;\n }\n if (use_pred) {\n if (q2 && q1 != q2) {\n q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;\n q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;\n if (q1 < 1)\n return AVERROR_INVALIDDATA;\n if (dc_pred_dir) {\n for (k = 1; k < 8; k++)\n block[k << v->left_blk_sh] += (ac_val[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;\n } else {\n for (k = 1; k < 8; k++)\n block[k << v->top_blk_sh] += (ac_val[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;\n }\n } else {\n if (dc_pred_dir) {\n for (k = 1; k < 8; k++)\n block[k << v->left_blk_sh] += ac_val[k];\n } else {\n for (k = 1; k < 8; k++)\n block[k << v->top_blk_sh] += ac_val[k + 8];\n }\n }\n }\n for (k = 1; k < 8; k++) {\n ac_val2[k ] = block[k << v->left_blk_sh];\n ac_val2[k + 8] = block[k << v->top_blk_sh];\n }\n for (k = 1; k < 64; k++)\n if (block[k]) {\n block[k] *= scale;\n if (!v->pquantizer)\n block[k] += (block[k] < 0) ? -mquant : mquant;\n }\n if (use_pred) i = 63;\n } else {\n int k;\n memset(ac_val2, 0, 16 * 2);\n if (dc_pred_dir) {\n if (use_pred) {\n memcpy(ac_val2, ac_val, 8 * 2);\n if (q2 && q1 != q2) {\n q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;\n q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;\n if (q1 < 1)\n return AVERROR_INVALIDDATA;\n for (k = 1; k < 8; k++)\n ac_val2[k] = (ac_val2[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;\n }\n }\n } else {\n if (use_pred) {\n memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);\n if (q2 && q1 != q2) {\n q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;\n q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;\n if (q1 < 1)\n return AVERROR_INVALIDDATA;\n for (k = 1; k < 8; k++)\n ac_val2[k + 8] = (ac_val2[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;\n }\n }\n }\n if (use_pred) {\n if (dc_pred_dir) {\n for (k = 1; k < 8; k++) {\n block[k << v->left_blk_sh] = ac_val2[k] * scale;\n if (!v->pquantizer && block[k << v->left_blk_sh])\n block[k << v->left_blk_sh] += (block[k << v->left_blk_sh] < 0) ? -mquant : mquant;\n }\n } else {\n for (k = 1; k < 8; k++) {\n block[k << v->top_blk_sh] = ac_val2[k + 8] * scale;\n if (!v->pquantizer && block[k << v->top_blk_sh])\n block[k << v->top_blk_sh] += (block[k << v->top_blk_sh] < 0) ? -mquant : mquant;\n }\n }\n i = 63;\n }\n }\n s->block_last_index[n] = i;\n return 0;\n}', 'static void vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip,\n int *value, int codingset)\n{\n GetBitContext *gb = &v->s.gb;\n int index, escape, run = 0, level = 0, lst = 0;\n index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3);\n if (index != ff_vc1_ac_sizes[codingset] - 1) {\n run = vc1_index_decode_table[codingset][index][0];\n level = vc1_index_decode_table[codingset][index][1];\n lst = index >= vc1_last_decode_table[codingset] || get_bits_left(gb) < 0;\n if (get_bits1(gb))\n level = -level;\n } else {\n escape = decode210(gb);\n if (escape != 2) {\n index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3);\n run = vc1_index_decode_table[codingset][index][0];\n level = vc1_index_decode_table[codingset][index][1];\n lst = index >= vc1_last_decode_table[codingset];\n if (escape == 0) {\n if (lst)\n level += vc1_last_delta_level_table[codingset][run];\n else\n level += vc1_delta_level_table[codingset][run];\n } else {\n if (lst)\n run += vc1_last_delta_run_table[codingset][level] + 1;\n else\n run += vc1_delta_run_table[codingset][level] + 1;\n }\n if (get_bits1(gb))\n level = -level;\n } else {\n int sign;\n lst = get_bits1(gb);\n if (v->s.esc3_level_length == 0) {\n if (v->pq < 8 || v->dquantfrm) {\n v->s.esc3_level_length = get_bits(gb, 3);\n if (!v->s.esc3_level_length)\n v->s.esc3_level_length = get_bits(gb, 2) + 8;\n } else {\n v->s.esc3_level_length = get_unary(gb, 1, 6) + 2;\n }\n v->s.esc3_run_length = 3 + get_bits(gb, 2);\n }\n run = get_bits(gb, v->s.esc3_run_length);\n sign = get_bits1(gb);\n level = get_bits(gb, v->s.esc3_level_length);\n if (sign)\n level = -level;\n }\n }\n *last = lst;\n *skip = run;\n *value = level;\n}']
34,880
0
https://github.com/libav/libav/blob/d6e49096c0c3c10ffb176761b0da150c93bedbf6/libavformat/gxfenc.c/#L197
static int gxf_write_mpeg_auxiliary(AVIOContext *pb, AVStream *st) { GXFStreamContext *sc = st->priv_data; char buffer[1024]; int size, starting_line; if (sc->iframes) { sc->p_per_gop = sc->pframes / sc->iframes; if (sc->pframes % sc->iframes) sc->p_per_gop++; if (sc->pframes) { sc->b_per_i_or_p = sc->bframes / sc->pframes; if (sc->bframes % sc->pframes) sc->b_per_i_or_p++; } if (sc->p_per_gop > 9) sc->p_per_gop = 9; if (sc->b_per_i_or_p > 9) sc->b_per_i_or_p = 9; } if (st->codecpar->height == 512 || st->codecpar->height == 608) starting_line = 7; else if (st->codecpar->height == 480) starting_line = 20; else starting_line = 23; size = snprintf(buffer, 1024, "Ver 1\nBr %.6f\nIpg 1\nPpi %d\nBpiop %d\n" "Pix 0\nCf %d\nCg %d\nSl %d\nnl16 %d\nVi 1\nf1 1\n", (float)st->codecpar->bit_rate, sc->p_per_gop, sc->b_per_i_or_p, st->codecpar->format == AV_PIX_FMT_YUV422P ? 2 : 1, sc->first_gop_closed == 1, starting_line, (st->codecpar->height + 15) / 16); avio_w8(pb, TRACK_MPG_AUX); avio_w8(pb, size + 1); avio_write(pb, (uint8_t *)buffer, size + 1); return size + 3; }
['static int gxf_write_mpeg_auxiliary(AVIOContext *pb, AVStream *st)\n{\n GXFStreamContext *sc = st->priv_data;\n char buffer[1024];\n int size, starting_line;\n if (sc->iframes) {\n sc->p_per_gop = sc->pframes / sc->iframes;\n if (sc->pframes % sc->iframes)\n sc->p_per_gop++;\n if (sc->pframes) {\n sc->b_per_i_or_p = sc->bframes / sc->pframes;\n if (sc->bframes % sc->pframes)\n sc->b_per_i_or_p++;\n }\n if (sc->p_per_gop > 9)\n sc->p_per_gop = 9;\n if (sc->b_per_i_or_p > 9)\n sc->b_per_i_or_p = 9;\n }\n if (st->codecpar->height == 512 || st->codecpar->height == 608)\n starting_line = 7;\n else if (st->codecpar->height == 480)\n starting_line = 20;\n else\n starting_line = 23;\n size = snprintf(buffer, 1024, "Ver 1\\nBr %.6f\\nIpg 1\\nPpi %d\\nBpiop %d\\n"\n "Pix 0\\nCf %d\\nCg %d\\nSl %d\\nnl16 %d\\nVi 1\\nf1 1\\n",\n (float)st->codecpar->bit_rate, sc->p_per_gop, sc->b_per_i_or_p,\n st->codecpar->format == AV_PIX_FMT_YUV422P ? 2 : 1, sc->first_gop_closed == 1,\n starting_line, (st->codecpar->height + 15) / 16);\n avio_w8(pb, TRACK_MPG_AUX);\n avio_w8(pb, size + 1);\n avio_write(pb, (uint8_t *)buffer, size + 1);\n return size + 3;\n}']
34,881
0
https://github.com/libav/libav/blob/6aa4e88106a554cef1d2294bb0a18b8f843032ef/libavformat/mpegts.c/#L692
static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t *buf, int buf_size) { GetBitContext gb; int au_start_flag = 0, au_end_flag = 0, ocr_flag = 0, idle_flag = 0; int padding_flag = 0, padding_bits = 0, inst_bitrate_flag = 0; int dts_flag = -1, cts_flag = -1; int64_t dts = AV_NOPTS_VALUE, cts = AV_NOPTS_VALUE; init_get_bits(&gb, buf, buf_size*8); if (sl->use_au_start) au_start_flag = get_bits1(&gb); if (sl->use_au_end) au_end_flag = get_bits1(&gb); if (!sl->use_au_start && !sl->use_au_end) au_start_flag = au_end_flag = 1; if (sl->ocr_len > 0) ocr_flag = get_bits1(&gb); if (sl->use_idle) idle_flag = get_bits1(&gb); if (sl->use_padding) padding_flag = get_bits1(&gb); if (padding_flag) padding_bits = get_bits(&gb, 3); if (!idle_flag && (!padding_flag || padding_bits != 0)) { if (sl->packet_seq_num_len) skip_bits_long(&gb, sl->packet_seq_num_len); if (sl->degr_prior_len) if (get_bits1(&gb)) skip_bits(&gb, sl->degr_prior_len); if (ocr_flag) skip_bits_long(&gb, sl->ocr_len); if (au_start_flag) { if (sl->use_rand_acc_pt) get_bits1(&gb); if (sl->au_seq_num_len > 0) skip_bits_long(&gb, sl->au_seq_num_len); if (sl->use_timestamps) { dts_flag = get_bits1(&gb); cts_flag = get_bits1(&gb); } } if (sl->inst_bitrate_len) inst_bitrate_flag = get_bits1(&gb); if (dts_flag == 1) dts = get_bits64(&gb, sl->timestamp_len); if (cts_flag == 1) cts = get_bits64(&gb, sl->timestamp_len); if (sl->au_len > 0) skip_bits_long(&gb, sl->au_len); if (inst_bitrate_flag) skip_bits_long(&gb, sl->inst_bitrate_len); } if (dts != AV_NOPTS_VALUE) pes->dts = dts; if (cts != AV_NOPTS_VALUE) pes->pts = cts; if (sl->timestamp_len && sl->timestamp_res) avpriv_set_pts_info(pes->st, sl->timestamp_len, 1, sl->timestamp_res); return (get_bits_count(&gb) + 7) >> 3; }
['static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t *buf, int buf_size)\n{\n GetBitContext gb;\n int au_start_flag = 0, au_end_flag = 0, ocr_flag = 0, idle_flag = 0;\n int padding_flag = 0, padding_bits = 0, inst_bitrate_flag = 0;\n int dts_flag = -1, cts_flag = -1;\n int64_t dts = AV_NOPTS_VALUE, cts = AV_NOPTS_VALUE;\n init_get_bits(&gb, buf, buf_size*8);\n if (sl->use_au_start)\n au_start_flag = get_bits1(&gb);\n if (sl->use_au_end)\n au_end_flag = get_bits1(&gb);\n if (!sl->use_au_start && !sl->use_au_end)\n au_start_flag = au_end_flag = 1;\n if (sl->ocr_len > 0)\n ocr_flag = get_bits1(&gb);\n if (sl->use_idle)\n idle_flag = get_bits1(&gb);\n if (sl->use_padding)\n padding_flag = get_bits1(&gb);\n if (padding_flag)\n padding_bits = get_bits(&gb, 3);\n if (!idle_flag && (!padding_flag || padding_bits != 0)) {\n if (sl->packet_seq_num_len)\n skip_bits_long(&gb, sl->packet_seq_num_len);\n if (sl->degr_prior_len)\n if (get_bits1(&gb))\n skip_bits(&gb, sl->degr_prior_len);\n if (ocr_flag)\n skip_bits_long(&gb, sl->ocr_len);\n if (au_start_flag) {\n if (sl->use_rand_acc_pt)\n get_bits1(&gb);\n if (sl->au_seq_num_len > 0)\n skip_bits_long(&gb, sl->au_seq_num_len);\n if (sl->use_timestamps) {\n dts_flag = get_bits1(&gb);\n cts_flag = get_bits1(&gb);\n }\n }\n if (sl->inst_bitrate_len)\n inst_bitrate_flag = get_bits1(&gb);\n if (dts_flag == 1)\n dts = get_bits64(&gb, sl->timestamp_len);\n if (cts_flag == 1)\n cts = get_bits64(&gb, sl->timestamp_len);\n if (sl->au_len > 0)\n skip_bits_long(&gb, sl->au_len);\n if (inst_bitrate_flag)\n skip_bits_long(&gb, sl->inst_bitrate_len);\n }\n if (dts != AV_NOPTS_VALUE)\n pes->dts = dts;\n if (cts != AV_NOPTS_VALUE)\n pes->pts = cts;\n if (sl->timestamp_len && sl->timestamp_res)\n avpriv_set_pts_info(pes->st, sl->timestamp_len, 1, sl->timestamp_res);\n return (get_bits_count(&gb) + 7) >> 3;\n}', 'static inline void init_get_bits(GetBitContext *s, const uint8_t *buffer,\n int bit_size)\n{\n int buffer_size = (bit_size+7)>>3;\n if (buffer_size < 0 || bit_size < 0) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n }\n s->buffer = buffer;\n s->size_in_bits = bit_size;\n#if !UNCHECKED_BITSTREAM_READER\n s->size_in_bits_plus8 = bit_size + 8;\n#endif\n s->buffer_end = buffer + buffer_size;\n s->index = 0;\n}', 'static inline unsigned int get_bits1(GetBitContext *s)\n{\n unsigned int index = s->index;\n uint8_t result = s->buffer[index>>3];\n#ifdef BITSTREAM_READER_LE\n result >>= index & 7;\n result &= 1;\n#else\n result <<= index & 7;\n result >>= 8 - 1;\n#endif\n#if !UNCHECKED_BITSTREAM_READER\n if (s->index < s->size_in_bits_plus8)\n#endif\n index++;\n s->index = index;\n return result;\n}']
34,882
0
https://github.com/libav/libav/blob/12f0388f9cb32016ac0dacaeca631b088b29bb96/libavcodec/wmv2enc.c/#L48
static int encode_ext_header(Wmv2Context *w) { MpegEncContext *const s = &w->s; PutBitContext pb; int code; init_put_bits(&pb, s->avctx->extradata, s->avctx->extradata_size); put_bits(&pb, 5, s->avctx->time_base.den / s->avctx->time_base.num); put_bits(&pb, 11, FFMIN(s->bit_rate / 1024, 2047)); put_bits(&pb, 1, w->mspel_bit = 1); put_bits(&pb, 1, s->loop_filter); put_bits(&pb, 1, w->abt_flag = 1); put_bits(&pb, 1, w->j_type_bit = 1); put_bits(&pb, 1, w->top_left_mv_flag = 0); put_bits(&pb, 1, w->per_mb_rl_bit = 1); put_bits(&pb, 3, code = 1); flush_put_bits(&pb); s->slice_height = s->mb_height / code; return 0; }
['static int encode_ext_header(Wmv2Context *w)\n{\n MpegEncContext *const s = &w->s;\n PutBitContext pb;\n int code;\n init_put_bits(&pb, s->avctx->extradata, s->avctx->extradata_size);\n put_bits(&pb, 5, s->avctx->time_base.den / s->avctx->time_base.num);\n put_bits(&pb, 11, FFMIN(s->bit_rate / 1024, 2047));\n put_bits(&pb, 1, w->mspel_bit = 1);\n put_bits(&pb, 1, s->loop_filter);\n put_bits(&pb, 1, w->abt_flag = 1);\n put_bits(&pb, 1, w->j_type_bit = 1);\n put_bits(&pb, 1, w->top_left_mv_flag = 0);\n put_bits(&pb, 1, w->per_mb_rl_bit = 1);\n put_bits(&pb, 3, code = 1);\n flush_put_bits(&pb);\n s->slice_height = s->mb_height / code;\n return 0;\n}', 'static inline void init_put_bits(PutBitContext *s, uint8_t *buffer,\n int buffer_size)\n{\n if (buffer_size < 0) {\n buffer_size = 0;\n buffer = NULL;\n }\n s->size_in_bits = 8 * buffer_size;\n s->buf = buffer;\n s->buf_end = s->buf + buffer_size;\n s->buf_ptr = s->buf;\n s->bit_left = 32;\n s->bit_buf = 0;\n}', 'static inline void put_bits(PutBitContext *s, int n, unsigned int value)\n{\n unsigned int bit_buf;\n int bit_left;\n assert(n <= 31 && value < (1U << n));\n bit_buf = s->bit_buf;\n bit_left = s->bit_left;\n#ifdef BITSTREAM_WRITER_LE\n bit_buf |= value << (32 - bit_left);\n if (n >= bit_left) {\n AV_WL32(s->buf_ptr, bit_buf);\n s->buf_ptr += 4;\n bit_buf = (bit_left == 32) ? 0 : value >> bit_left;\n bit_left += 32;\n }\n bit_left -= n;\n#else\n if (n < bit_left) {\n bit_buf = (bit_buf << n) | value;\n bit_left -= n;\n } else {\n bit_buf <<= bit_left;\n bit_buf |= value >> (n - bit_left);\n AV_WB32(s->buf_ptr, bit_buf);\n s->buf_ptr += 4;\n bit_left += 32 - n;\n bit_buf = value;\n }\n#endif\n s->bit_buf = bit_buf;\n s->bit_left = bit_left;\n}', 'static inline void flush_put_bits(PutBitContext *s)\n{\n#ifndef BITSTREAM_WRITER_LE\n if (s->bit_left < 32)\n s->bit_buf <<= s->bit_left;\n#endif\n while (s->bit_left < 32) {\n#ifdef BITSTREAM_WRITER_LE\n *s->buf_ptr++ = s->bit_buf;\n s->bit_buf >>= 8;\n#else\n *s->buf_ptr++ = s->bit_buf >> 24;\n s->bit_buf <<= 8;\n#endif\n s->bit_left += 8;\n }\n s->bit_left = 32;\n s->bit_buf = 0;\n}']
34,883
0
https://github.com/libav/libav/blob/48aef27f5232794e70ecef0d347b9f65e27a9bad/libavformat/udp.c/#L524
static int udp_open(URLContext *h, const char *uri, int flags) { char hostname[1024], localaddr[1024] = ""; int port, udp_fd = -1, tmp, bind_ret = -1; UDPContext *s = h->priv_data; int is_output; const char *p; char buf[256]; struct sockaddr_storage my_addr; socklen_t len; int i, num_include_sources = 0, num_exclude_sources = 0; char *include_sources[32], *exclude_sources[32]; h->is_streamed = 1; h->max_packet_size = 1472; is_output = !(flags & AVIO_FLAG_READ); if (s->buffer_size < 0) s->buffer_size = is_output ? UDP_TX_BUF_SIZE : UDP_MAX_PKT_SIZE; if (s->sources) { if (parse_source_list(s->sources, include_sources, &num_include_sources, FF_ARRAY_ELEMS(include_sources))) goto fail; } if (s->block) { if (parse_source_list(s->block, exclude_sources, &num_exclude_sources, FF_ARRAY_ELEMS(exclude_sources))) goto fail; } if (s->pkt_size) h->max_packet_size = s->pkt_size; p = strchr(uri, '?'); if (p) { if (av_find_info_tag(buf, sizeof(buf), "reuse", p)) { char *endptr = NULL; s->reuse_socket = strtol(buf, &endptr, 10); if (buf == endptr) s->reuse_socket = 1; } if (av_find_info_tag(buf, sizeof(buf), "ttl", p)) { s->ttl = strtol(buf, NULL, 10); } if (av_find_info_tag(buf, sizeof(buf), "localport", p)) { s->local_port = strtol(buf, NULL, 10); } if (av_find_info_tag(buf, sizeof(buf), "pkt_size", p)) { h->max_packet_size = strtol(buf, NULL, 10); } if (av_find_info_tag(buf, sizeof(buf), "buffer_size", p)) { s->buffer_size = strtol(buf, NULL, 10); } if (av_find_info_tag(buf, sizeof(buf), "connect", p)) { s->is_connected = strtol(buf, NULL, 10); } if (av_find_info_tag(buf, sizeof(buf), "localaddr", p)) { av_strlcpy(localaddr, buf, sizeof(localaddr)); } if (av_find_info_tag(buf, sizeof(buf), "sources", p)) { if (parse_source_list(buf, include_sources, &num_include_sources, FF_ARRAY_ELEMS(include_sources))) goto fail; } if (av_find_info_tag(buf, sizeof(buf), "block", p)) { if (parse_source_list(buf, exclude_sources, &num_exclude_sources, FF_ARRAY_ELEMS(exclude_sources))) goto fail; } } av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri); if (hostname[0] == '\0' || hostname[0] == '?') { if (!(flags & AVIO_FLAG_READ)) goto fail; } else { if (ff_udp_set_remote_url(h, uri) < 0) goto fail; } if ((s->is_multicast || !s->local_port) && (h->flags & AVIO_FLAG_READ)) s->local_port = port; if (localaddr[0]) udp_fd = udp_socket_create(s, &my_addr, &len, localaddr); else udp_fd = udp_socket_create(s, &my_addr, &len, s->localaddr); if (udp_fd < 0) goto fail; if (s->reuse_socket > 0 || (s->is_multicast && s->reuse_socket < 0)) { s->reuse_socket = 1; if (setsockopt (udp_fd, SOL_SOCKET, SO_REUSEADDR, &(s->reuse_socket), sizeof(s->reuse_socket)) != 0) goto fail; } if (s->is_multicast && !(h->flags & AVIO_FLAG_WRITE)) { bind_ret = bind(udp_fd,(struct sockaddr *)&s->dest_addr, len); } if (bind_ret < 0 && bind(udp_fd,(struct sockaddr *)&my_addr, len) < 0) { log_net_error(h, AV_LOG_ERROR, "bind failed"); goto fail; } len = sizeof(my_addr); getsockname(udp_fd, (struct sockaddr *)&my_addr, &len); s->local_port = udp_port(&my_addr, len); if (s->is_multicast) { if (h->flags & AVIO_FLAG_WRITE) { if (udp_set_multicast_ttl(udp_fd, s->ttl, (struct sockaddr *)&s->dest_addr) < 0) goto fail; } if (h->flags & AVIO_FLAG_READ) { if (num_include_sources && num_exclude_sources) { av_log(h, AV_LOG_ERROR, "Simultaneously including and excluding multicast sources is not supported\n"); goto fail; } if (num_include_sources) { if (udp_set_multicast_sources(udp_fd, (struct sockaddr *)&s->dest_addr, s->dest_addr_len, include_sources, num_include_sources, 1) < 0) goto fail; } else { if (udp_join_multicast_group(udp_fd, (struct sockaddr *)&s->dest_addr) < 0) goto fail; } if (num_exclude_sources) { if (udp_set_multicast_sources(udp_fd, (struct sockaddr *)&s->dest_addr, s->dest_addr_len, exclude_sources, num_exclude_sources, 0) < 0) goto fail; } } } if (is_output) { tmp = s->buffer_size; if (setsockopt(udp_fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp)) < 0) { log_net_error(h, AV_LOG_ERROR, "setsockopt(SO_SNDBUF)"); goto fail; } } else { tmp = s->buffer_size; if (setsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &tmp, sizeof(tmp)) < 0) { log_net_error(h, AV_LOG_WARNING, "setsockopt(SO_RECVBUF)"); } ff_socket_nonblock(udp_fd, 1); } if (s->is_connected) { if (connect(udp_fd, (struct sockaddr *) &s->dest_addr, s->dest_addr_len)) { log_net_error(h, AV_LOG_ERROR, "connect"); goto fail; } } for (i = 0; i < num_include_sources; i++) av_freep(&include_sources[i]); for (i = 0; i < num_exclude_sources; i++) av_freep(&exclude_sources[i]); s->udp_fd = udp_fd; return 0; fail: if (udp_fd >= 0) closesocket(udp_fd); for (i = 0; i < num_include_sources; i++) av_freep(&include_sources[i]); for (i = 0; i < num_exclude_sources; i++) av_freep(&exclude_sources[i]); return AVERROR(EIO); }
['static int udp_open(URLContext *h, const char *uri, int flags)\n{\n char hostname[1024], localaddr[1024] = "";\n int port, udp_fd = -1, tmp, bind_ret = -1;\n UDPContext *s = h->priv_data;\n int is_output;\n const char *p;\n char buf[256];\n struct sockaddr_storage my_addr;\n socklen_t len;\n int i, num_include_sources = 0, num_exclude_sources = 0;\n char *include_sources[32], *exclude_sources[32];\n h->is_streamed = 1;\n h->max_packet_size = 1472;\n is_output = !(flags & AVIO_FLAG_READ);\n if (s->buffer_size < 0)\n s->buffer_size = is_output ? UDP_TX_BUF_SIZE : UDP_MAX_PKT_SIZE;\n if (s->sources) {\n if (parse_source_list(s->sources, include_sources,\n &num_include_sources,\n FF_ARRAY_ELEMS(include_sources)))\n goto fail;\n }\n if (s->block) {\n if (parse_source_list(s->block, exclude_sources, &num_exclude_sources,\n FF_ARRAY_ELEMS(exclude_sources)))\n goto fail;\n }\n if (s->pkt_size)\n h->max_packet_size = s->pkt_size;\n p = strchr(uri, \'?\');\n if (p) {\n if (av_find_info_tag(buf, sizeof(buf), "reuse", p)) {\n char *endptr = NULL;\n s->reuse_socket = strtol(buf, &endptr, 10);\n if (buf == endptr)\n s->reuse_socket = 1;\n }\n if (av_find_info_tag(buf, sizeof(buf), "ttl", p)) {\n s->ttl = strtol(buf, NULL, 10);\n }\n if (av_find_info_tag(buf, sizeof(buf), "localport", p)) {\n s->local_port = strtol(buf, NULL, 10);\n }\n if (av_find_info_tag(buf, sizeof(buf), "pkt_size", p)) {\n h->max_packet_size = strtol(buf, NULL, 10);\n }\n if (av_find_info_tag(buf, sizeof(buf), "buffer_size", p)) {\n s->buffer_size = strtol(buf, NULL, 10);\n }\n if (av_find_info_tag(buf, sizeof(buf), "connect", p)) {\n s->is_connected = strtol(buf, NULL, 10);\n }\n if (av_find_info_tag(buf, sizeof(buf), "localaddr", p)) {\n av_strlcpy(localaddr, buf, sizeof(localaddr));\n }\n if (av_find_info_tag(buf, sizeof(buf), "sources", p)) {\n if (parse_source_list(buf, include_sources, &num_include_sources,\n FF_ARRAY_ELEMS(include_sources)))\n goto fail;\n }\n if (av_find_info_tag(buf, sizeof(buf), "block", p)) {\n if (parse_source_list(buf, exclude_sources, &num_exclude_sources,\n FF_ARRAY_ELEMS(exclude_sources)))\n goto fail;\n }\n }\n av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);\n if (hostname[0] == \'\\0\' || hostname[0] == \'?\') {\n if (!(flags & AVIO_FLAG_READ))\n goto fail;\n } else {\n if (ff_udp_set_remote_url(h, uri) < 0)\n goto fail;\n }\n if ((s->is_multicast || !s->local_port) && (h->flags & AVIO_FLAG_READ))\n s->local_port = port;\n if (localaddr[0])\n udp_fd = udp_socket_create(s, &my_addr, &len, localaddr);\n else\n udp_fd = udp_socket_create(s, &my_addr, &len, s->localaddr);\n if (udp_fd < 0)\n goto fail;\n if (s->reuse_socket > 0 || (s->is_multicast && s->reuse_socket < 0)) {\n s->reuse_socket = 1;\n if (setsockopt (udp_fd, SOL_SOCKET, SO_REUSEADDR, &(s->reuse_socket), sizeof(s->reuse_socket)) != 0)\n goto fail;\n }\n if (s->is_multicast && !(h->flags & AVIO_FLAG_WRITE)) {\n bind_ret = bind(udp_fd,(struct sockaddr *)&s->dest_addr, len);\n }\n if (bind_ret < 0 && bind(udp_fd,(struct sockaddr *)&my_addr, len) < 0) {\n log_net_error(h, AV_LOG_ERROR, "bind failed");\n goto fail;\n }\n len = sizeof(my_addr);\n getsockname(udp_fd, (struct sockaddr *)&my_addr, &len);\n s->local_port = udp_port(&my_addr, len);\n if (s->is_multicast) {\n if (h->flags & AVIO_FLAG_WRITE) {\n if (udp_set_multicast_ttl(udp_fd, s->ttl, (struct sockaddr *)&s->dest_addr) < 0)\n goto fail;\n }\n if (h->flags & AVIO_FLAG_READ) {\n if (num_include_sources && num_exclude_sources) {\n av_log(h, AV_LOG_ERROR, "Simultaneously including and excluding multicast sources is not supported\\n");\n goto fail;\n }\n if (num_include_sources) {\n if (udp_set_multicast_sources(udp_fd, (struct sockaddr *)&s->dest_addr, s->dest_addr_len, include_sources, num_include_sources, 1) < 0)\n goto fail;\n } else {\n if (udp_join_multicast_group(udp_fd, (struct sockaddr *)&s->dest_addr) < 0)\n goto fail;\n }\n if (num_exclude_sources) {\n if (udp_set_multicast_sources(udp_fd, (struct sockaddr *)&s->dest_addr, s->dest_addr_len, exclude_sources, num_exclude_sources, 0) < 0)\n goto fail;\n }\n }\n }\n if (is_output) {\n tmp = s->buffer_size;\n if (setsockopt(udp_fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp)) < 0) {\n log_net_error(h, AV_LOG_ERROR, "setsockopt(SO_SNDBUF)");\n goto fail;\n }\n } else {\n tmp = s->buffer_size;\n if (setsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &tmp, sizeof(tmp)) < 0) {\n log_net_error(h, AV_LOG_WARNING, "setsockopt(SO_RECVBUF)");\n }\n ff_socket_nonblock(udp_fd, 1);\n }\n if (s->is_connected) {\n if (connect(udp_fd, (struct sockaddr *) &s->dest_addr, s->dest_addr_len)) {\n log_net_error(h, AV_LOG_ERROR, "connect");\n goto fail;\n }\n }\n for (i = 0; i < num_include_sources; i++)\n av_freep(&include_sources[i]);\n for (i = 0; i < num_exclude_sources; i++)\n av_freep(&exclude_sources[i]);\n s->udp_fd = udp_fd;\n return 0;\n fail:\n if (udp_fd >= 0)\n closesocket(udp_fd);\n for (i = 0; i < num_include_sources; i++)\n av_freep(&include_sources[i]);\n for (i = 0; i < num_exclude_sources; i++)\n av_freep(&exclude_sources[i]);\n return AVERROR(EIO);\n}']
34,884
0
https://github.com/libav/libav/blob/ab3554e1a7c04a5ea30f9c905de92348478ef7c8/libavformat/hls.c/#L496
static int save_avio_options(AVFormatContext *s) { HLSContext *c = s->priv_data; static const char *opts[] = { "headers", "user_agent", NULL }; const char **opt = opts; uint8_t *buf; int ret = 0; while (*opt) { if (av_opt_get(s->pb, *opt, AV_OPT_SEARCH_CHILDREN, &buf) >= 0) { ret = av_dict_set(&c->avio_opts, *opt, buf, AV_DICT_DONT_STRDUP_VAL); if (ret < 0) return ret; } opt++; } return ret; }
['static int save_avio_options(AVFormatContext *s)\n{\n HLSContext *c = s->priv_data;\n static const char *opts[] = { "headers", "user_agent", NULL };\n const char **opt = opts;\n uint8_t *buf;\n int ret = 0;\n while (*opt) {\n if (av_opt_get(s->pb, *opt, AV_OPT_SEARCH_CHILDREN, &buf) >= 0) {\n ret = av_dict_set(&c->avio_opts, *opt, buf,\n AV_DICT_DONT_STRDUP_VAL);\n if (ret < 0)\n return ret;\n }\n opt++;\n }\n return ret;\n}', 'int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)\n{\n void *dst, *target_obj;\n const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);\n uint8_t *bin, buf[128];\n int len, i, ret;\n if (!o || !target_obj)\n return AVERROR_OPTION_NOT_FOUND;\n dst = (uint8_t *)target_obj + o->offset;\n buf[0] = 0;\n switch (o->type) {\n case AV_OPT_TYPE_FLAGS:\n ret = snprintf(buf, sizeof(buf), "0x%08X", *(int *)dst);\n break;\n case AV_OPT_TYPE_INT:\n ret = snprintf(buf, sizeof(buf), "%d", *(int *)dst);\n break;\n case AV_OPT_TYPE_INT64:\n ret = snprintf(buf, sizeof(buf), "%" PRId64, *(int64_t *)dst);\n break;\n case AV_OPT_TYPE_FLOAT:\n ret = snprintf(buf, sizeof(buf), "%f", *(float *)dst);\n break;\n case AV_OPT_TYPE_DOUBLE:\n ret = snprintf(buf, sizeof(buf), "%f", *(double *)dst);\n break;\n case AV_OPT_TYPE_RATIONAL:\n ret = snprintf(buf, sizeof(buf), "%d/%d", ((AVRational *)dst)->num,\n ((AVRational *)dst)->den);\n break;\n case AV_OPT_TYPE_STRING:\n if (*(uint8_t **)dst)\n *out_val = av_strdup(*(uint8_t **)dst);\n else\n *out_val = av_strdup("");\n return *out_val ? 0 : AVERROR(ENOMEM);\n case AV_OPT_TYPE_BINARY:\n len = *(int *)(((uint8_t *)dst) + sizeof(uint8_t *));\n if ((uint64_t)len * 2 + 1 > INT_MAX)\n return AVERROR(EINVAL);\n if (!(*out_val = av_malloc(len * 2 + 1)))\n return AVERROR(ENOMEM);\n bin = *(uint8_t **)dst;\n for (i = 0; i < len; i++)\n snprintf(*out_val + i * 2, 3, "%02X", bin[i]);\n return 0;\n default:\n return AVERROR(EINVAL);\n }\n if (ret >= sizeof(buf))\n return AVERROR(EINVAL);\n *out_val = av_strdup(buf);\n return *out_val ? 0 : AVERROR(ENOMEM);\n}', 'char *av_strdup(const char *s)\n{\n char *ptr = NULL;\n if (s) {\n int len = strlen(s) + 1;\n ptr = av_realloc(NULL, len);\n if (ptr)\n memcpy(ptr, s, len);\n }\n return ptr;\n}', 'void *av_realloc(void *ptr, size_t size)\n{\n if (size > (INT_MAX - 16))\n return NULL;\n#if HAVE_ALIGNED_MALLOC\n return _aligned_realloc(ptr, size, 32);\n#else\n return realloc(ptr, size);\n#endif\n}', 'int av_dict_set(AVDictionary **pm, const char *key, const char *value,\n int flags)\n{\n AVDictionary *m = *pm;\n AVDictionaryEntry *tag = av_dict_get(m, key, NULL, flags);\n char *oldval = NULL;\n int allocated = !!m;\n if (!m)\n m = *pm = av_mallocz(sizeof(*m));\n if (!m)\n return AVERROR(ENOMEM);\n if (tag) {\n if (flags & AV_DICT_DONT_OVERWRITE) {\n if (flags & AV_DICT_DONT_STRDUP_KEY) av_free(key);\n if (flags & AV_DICT_DONT_STRDUP_VAL) av_free(value);\n return 0;\n }\n if (flags & AV_DICT_APPEND)\n oldval = tag->value;\n else\n av_free(tag->value);\n av_free(tag->key);\n *tag = m->elems[--m->count];\n } else {\n int ret = av_reallocp_array(&m->elems,\n m->count + 1, sizeof(*m->elems));\n if (ret < 0) {\n if (allocated)\n av_freep(pm);\n return ret;\n }\n }\n if (value) {\n if (flags & AV_DICT_DONT_STRDUP_KEY)\n m->elems[m->count].key = key;\n else\n m->elems[m->count].key = av_strdup(key);\n if (flags & AV_DICT_DONT_STRDUP_VAL) {\n m->elems[m->count].value = value;\n } else if (oldval && flags & AV_DICT_APPEND) {\n int len = strlen(oldval) + strlen(value) + 1;\n if (!(oldval = av_realloc(oldval, len)))\n return AVERROR(ENOMEM);\n av_strlcat(oldval, value, len);\n m->elems[m->count].value = oldval;\n } else\n m->elems[m->count].value = av_strdup(value);\n m->count++;\n }\n if (!m->count) {\n av_free(m->elems);\n av_freep(pm);\n }\n return 0;\n}', 'int av_reallocp_array(void *ptr, size_t nmemb, size_t size)\n{\n void *val;\n if (!size || nmemb >= INT_MAX / size)\n return AVERROR(ENOMEM);\n if (!nmemb) {\n av_freep(ptr);\n return 0;\n }\n memcpy(&val, ptr, sizeof(val));\n val = av_realloc(val, nmemb * size);\n if (!val) {\n av_freep(ptr);\n return AVERROR(ENOMEM);\n }\n memcpy(ptr, &val, sizeof(val));\n return 0;\n}']
34,885
0
https://github.com/openssl/openssl/blob/1fac96e4d6484a517f2ebe99b72016726391723c/crypto/bn/bn_lib.c/#L447
BIGNUM *bn_expand2(BIGNUM *b, int words) { BN_ULONG *A,*a; const BN_ULONG *B; int i; bn_check_top(b); if (words > b->max) { bn_check_top(b); if (BN_get_flags(b,BN_FLG_STATIC_DATA)) { BNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); return(NULL); } a=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1)); if (A == NULL) { BNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE); return(NULL); } #if 1 B=b->d; if (B != NULL) { #if 0 for (i=b->top&(~7); i>0; i-=8) { A[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3]; A[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7]; A+=8; B+=8; } switch (b->top&7) { case 7: A[6]=B[6]; case 6: A[5]=B[5]; case 5: A[4]=B[4]; case 4: A[3]=B[3]; case 3: A[2]=B[2]; case 2: A[1]=B[1]; case 1: A[0]=B[0]; case 0: ; } #else for (i=b->top>>2; i>0; i--,A+=4,B+=4) { BN_ULONG a0,a1,a2,a3; a0=B[0]; a1=B[1]; a2=B[2]; a3=B[3]; A[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3; } switch (b->top&3) { case 3: A[2]=B[2]; case 2: A[1]=B[1]; case 1: A[0]=B[0]; case 0: ; } #endif Free(b->d); } b->d=a; b->max=words; A= &(b->d[b->top]); for (i=(b->max - b->top)>>3; i>0; i--,A+=8) { A[0]=0; A[1]=0; A[2]=0; A[3]=0; A[4]=0; A[5]=0; A[6]=0; A[7]=0; } for (i=(b->max - b->top)&7; i>0; i--,A++) A[0]=0; #else memset(A,0,sizeof(BN_ULONG)*(words+1)); memcpy(A,b->d,sizeof(b->d[0])*b->top); b->d=a; b->max=words; #endif } return(b); }
['static DH *get_dh512(void)\n\t{\n\tDH *dh=NULL;\n\tif ((dh=DH_new()) == NULL) return(NULL);\n\tdh->p=BN_bin2bn(dh512_p,sizeof(dh512_p),NULL);\n\tdh->g=BN_bin2bn(dh512_g,sizeof(dh512_g),NULL);\n\tif ((dh->p == NULL) || (dh->g == NULL))\n\t\treturn(NULL);\n\treturn(dh);\n\t}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n\t{\n\tunsigned int i,m;\n\tunsigned int n;\n\tBN_ULONG l;\n\tif (ret == NULL) ret=BN_new();\n\tif (ret == NULL) return(NULL);\n\tl=0;\n\tn=len;\n\tif (n == 0)\n\t\t{\n\t\tret->top=0;\n\t\treturn(ret);\n\t\t}\n\tif (bn_expand(ret,(int)(n+2)*8) == NULL)\n\t\treturn(NULL);\n\ti=((n-1)/BN_BYTES)+1;\n\tm=((n-1)%(BN_BYTES));\n\tret->top=i;\n\twhile (n-- > 0)\n\t\t{\n\t\tl=(l<<8L)| *(s++);\n\t\tif (m-- == 0)\n\t\t\t{\n\t\t\tret->d[--i]=l;\n\t\t\tl=0;\n\t\t\tm=BN_BYTES-1;\n\t\t\t}\n\t\t}\n\tbn_fix_top(ret);\n\treturn(ret);\n\t}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n\t{\n\tBN_ULONG *A,*a;\n\tconst BN_ULONG *B;\n\tint i;\n\tbn_check_top(b);\n\tif (words > b->max)\n\t\t{\n\t\tbn_check_top(b);\n\t\tif (BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\ta=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1));\n\t\tif (A == NULL)\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE);\n\t\t\treturn(NULL);\n\t\t\t}\n#if 1\n\t\tB=b->d;\n\t\tif (B != NULL)\n\t\t\t{\n#if 0\n\t\t\tfor (i=b->top&(~7); i>0; i-=8)\n\t\t\t\t{\n\t\t\t\tA[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3];\n\t\t\t\tA[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7];\n\t\t\t\tA+=8;\n\t\t\t\tB+=8;\n\t\t\t\t}\n\t\t\tswitch (b->top&7)\n\t\t\t\t{\n\t\t\tcase 7:\n\t\t\t\tA[6]=B[6];\n\t\t\tcase 6:\n\t\t\t\tA[5]=B[5];\n\t\t\tcase 5:\n\t\t\t\tA[4]=B[4];\n\t\t\tcase 4:\n\t\t\t\tA[3]=B[3];\n\t\t\tcase 3:\n\t\t\t\tA[2]=B[2];\n\t\t\tcase 2:\n\t\t\t\tA[1]=B[1];\n\t\t\tcase 1:\n\t\t\t\tA[0]=B[0];\n\t\t\tcase 0:\n\t\t\t\t;\n\t\t\t\t}\n#else\n\t\t\tfor (i=b->top>>2; i>0; i--,A+=4,B+=4)\n\t\t\t\t{\n\t\t\t\tBN_ULONG a0,a1,a2,a3;\n\t\t\t\ta0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];\n\t\t\t\tA[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;\n\t\t\t\t}\n\t\t\tswitch (b->top&3)\n\t\t\t\t{\n\t\t\t\tcase 3:\tA[2]=B[2];\n\t\t\t\tcase 2:\tA[1]=B[1];\n\t\t\t\tcase 1:\tA[0]=B[0];\n\t\t\t\tcase 0:\t;\n\t\t\t\t}\n#endif\n\t\t\tFree(b->d);\n\t\t\t}\n\t\tb->d=a;\n\t\tb->max=words;\n\t\tA= &(b->d[b->top]);\n\t\tfor (i=(b->max - b->top)>>3; i>0; i--,A+=8)\n\t\t\t{\n\t\t\tA[0]=0; A[1]=0; A[2]=0; A[3]=0;\n\t\t\tA[4]=0; A[5]=0; A[6]=0; A[7]=0;\n\t\t\t}\n\t\tfor (i=(b->max - b->top)&7; i>0; i--,A++)\n\t\t\tA[0]=0;\n#else\n\t\t\tmemset(A,0,sizeof(BN_ULONG)*(words+1));\n\t\t\tmemcpy(A,b->d,sizeof(b->d[0])*b->top);\n\t\t\tb->d=a;\n\t\t\tb->max=words;\n#endif\n\t\t}\n\treturn(b);\n\t}']
34,886
0
https://github.com/openssl/openssl/blob/ff64702b3d83d4c77756e0fd7b624e2165dbbdf0/crypto/packet.c/#L52
int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes) { if (!ossl_assert(pkt->subs != NULL && len != 0)) return 0; if (pkt->maxsize - pkt->written < len) return 0; if (pkt->buf != NULL && (pkt->buf->length - pkt->written < len)) { size_t newlen; size_t reflen; reflen = (len > pkt->buf->length) ? len : pkt->buf->length; if (reflen > SIZE_MAX / 2) { newlen = SIZE_MAX; } else { newlen = reflen * 2; if (newlen < DEFAULT_BUF_SIZE) newlen = DEFAULT_BUF_SIZE; } if (BUF_MEM_grow(pkt->buf, newlen) == 0) return 0; } if (allocbytes != NULL) *allocbytes = WPACKET_get_curr(pkt); return 1; }
['EXT_RETURN tls_construct_stoc_next_proto_neg(SSL *s, WPACKET *pkt,\n unsigned int context, X509 *x,\n size_t chainidx)\n{\n const unsigned char *npa;\n unsigned int npalen;\n int ret;\n int npn_seen = s->s3.npn_seen;\n s->s3.npn_seen = 0;\n if (!npn_seen || s->ctx->ext.npn_advertised_cb == NULL)\n return EXT_RETURN_NOT_SENT;\n ret = s->ctx->ext.npn_advertised_cb(s, &npa, &npalen,\n s->ctx->ext.npn_advertised_cb_arg);\n if (ret == SSL_TLSEXT_ERR_OK) {\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_next_proto_neg)\n || !WPACKET_sub_memcpy_u16(pkt, npa, npalen)) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR,\n SSL_F_TLS_CONSTRUCT_STOC_NEXT_PROTO_NEG,\n ERR_R_INTERNAL_ERROR);\n return EXT_RETURN_FAIL;\n }\n s->s3.npn_seen = 1;\n }\n return EXT_RETURN_SENT;\n}', 'int WPACKET_put_bytes__(WPACKET *pkt, unsigned int val, size_t size)\n{\n unsigned char *data;\n if (!ossl_assert(size <= sizeof(unsigned int))\n || !WPACKET_allocate_bytes(pkt, size, &data)\n || !put_value(data, val, size))\n return 0;\n return 1;\n}', 'int WPACKET_sub_memcpy__(WPACKET *pkt, const void *src, size_t len,\n size_t lenbytes)\n{\n if (!WPACKET_start_sub_packet_len__(pkt, lenbytes)\n || !WPACKET_memcpy(pkt, src, len)\n || !WPACKET_close(pkt))\n return 0;\n return 1;\n}', 'int WPACKET_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes)\n{\n WPACKET_SUB *sub;\n unsigned char *lenchars;\n if (!ossl_assert(pkt->subs != NULL))\n return 0;\n if ((sub = OPENSSL_zalloc(sizeof(*sub))) == NULL) {\n SSLerr(SSL_F_WPACKET_START_SUB_PACKET_LEN__, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n sub->parent = pkt->subs;\n pkt->subs = sub;\n sub->pwritten = pkt->written + lenbytes;\n sub->lenbytes = lenbytes;\n if (lenbytes == 0) {\n sub->packet_len = 0;\n return 1;\n }\n sub->packet_len = pkt->written;\n if (!WPACKET_allocate_bytes(pkt, lenbytes, &lenchars))\n return 0;\n return 1;\n}', 'int WPACKET_memcpy(WPACKET *pkt, const void *src, size_t len)\n{\n unsigned char *dest;\n if (len == 0)\n return 1;\n if (!WPACKET_allocate_bytes(pkt, len, &dest))\n return 0;\n if (dest != NULL)\n memcpy(dest, src, len);\n return 1;\n}', 'int WPACKET_allocate_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n if (!WPACKET_reserve_bytes(pkt, len, allocbytes))\n return 0;\n pkt->written += len;\n pkt->curr += len;\n return 1;\n}', 'int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n if (!ossl_assert(pkt->subs != NULL && len != 0))\n return 0;\n if (pkt->maxsize - pkt->written < len)\n return 0;\n if (pkt->buf != NULL && (pkt->buf->length - pkt->written < len)) {\n size_t newlen;\n size_t reflen;\n reflen = (len > pkt->buf->length) ? len : pkt->buf->length;\n if (reflen > SIZE_MAX / 2) {\n newlen = SIZE_MAX;\n } else {\n newlen = reflen * 2;\n if (newlen < DEFAULT_BUF_SIZE)\n newlen = DEFAULT_BUF_SIZE;\n }\n if (BUF_MEM_grow(pkt->buf, newlen) == 0)\n return 0;\n }\n if (allocbytes != NULL)\n *allocbytes = WPACKET_get_curr(pkt);\n return 1;\n}']
34,887
0
https://github.com/libav/libav/blob/c0994e39d7fd63b4f4adfe4714fa6e41bff82a7c/libavformat/movenc.c/#L2958
static void mov_create_chapter_track(AVFormatContext *s, int tracknum) { MOVMuxContext *mov = s->priv_data; MOVTrack *track = &mov->tracks[tracknum]; AVPacket pkt = { .stream_index = tracknum, .flags = AV_PKT_FLAG_KEY }; int i, len; track->mode = mov->mode; track->tag = MKTAG('t','e','x','t'); track->timescale = MOV_TIMESCALE; track->enc = avcodec_alloc_context3(NULL); track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE; for (i = 0; i < s->nb_chapters; i++) { AVChapter *c = s->chapters[i]; AVDictionaryEntry *t; int64_t end = av_rescale_q(c->end, c->time_base, (AVRational){1,MOV_TIMESCALE}); pkt.pts = pkt.dts = av_rescale_q(c->start, c->time_base, (AVRational){1,MOV_TIMESCALE}); pkt.duration = end - pkt.dts; if ((t = av_dict_get(c->metadata, "title", NULL, 0))) { len = strlen(t->value); pkt.size = len+2; pkt.data = av_malloc(pkt.size); AV_WB16(pkt.data, len); memcpy(pkt.data+2, t->value, len); ff_mov_write_packet(s, &pkt); av_freep(&pkt.data); } } }
['static void mov_create_chapter_track(AVFormatContext *s, int tracknum)\n{\n MOVMuxContext *mov = s->priv_data;\n MOVTrack *track = &mov->tracks[tracknum];\n AVPacket pkt = { .stream_index = tracknum, .flags = AV_PKT_FLAG_KEY };\n int i, len;\n track->mode = mov->mode;\n track->tag = MKTAG(\'t\',\'e\',\'x\',\'t\');\n track->timescale = MOV_TIMESCALE;\n track->enc = avcodec_alloc_context3(NULL);\n track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;\n for (i = 0; i < s->nb_chapters; i++) {\n AVChapter *c = s->chapters[i];\n AVDictionaryEntry *t;\n int64_t end = av_rescale_q(c->end, c->time_base, (AVRational){1,MOV_TIMESCALE});\n pkt.pts = pkt.dts = av_rescale_q(c->start, c->time_base, (AVRational){1,MOV_TIMESCALE});\n pkt.duration = end - pkt.dts;\n if ((t = av_dict_get(c->metadata, "title", NULL, 0))) {\n len = strlen(t->value);\n pkt.size = len+2;\n pkt.data = av_malloc(pkt.size);\n AV_WB16(pkt.data, len);\n memcpy(pkt.data+2, t->value, len);\n ff_mov_write_packet(s, &pkt);\n av_freep(&pkt.data);\n }\n }\n}', 'AVCodecContext *avcodec_alloc_context3(AVCodec *codec){\n AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));\n if(avctx==NULL) return NULL;\n if(avcodec_get_context_defaults3(avctx, codec) < 0){\n av_free(avctx);\n return NULL;\n }\n return avctx;\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-32) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+32);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&31) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,32,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(32,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}', 'int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){\n int64_t b= bq.num * (int64_t)cq.den;\n int64_t c= cq.num * (int64_t)bq.den;\n return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);\n}', 'static av_always_inline av_const uint16_t av_bswap16(uint16_t x)\n{\n x= (x>>8) | (x<<8);\n return x;\n}']
34,888
0
https://github.com/openssl/openssl/blob/7f7eb90b8ac55997c5c825bb3ebcfe28611e06f5/ssl/statem/statem_lib.c/#L908
static int ssl_add_cert_chain(SSL *s, WPACKET *pkt, CERT_PKEY *cpk, int *al) { int i, chain_count; X509 *x; STACK_OF(X509) *extra_certs; STACK_OF(X509) *chain = NULL; X509_STORE *chain_store; int tmpal = SSL_AD_INTERNAL_ERROR; if (cpk == NULL || cpk->x509 == NULL) return 1; x = cpk->x509; if (cpk->chain != NULL) extra_certs = cpk->chain; else extra_certs = s->ctx->extra_certs; if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || extra_certs) chain_store = NULL; else if (s->cert->chain_store) chain_store = s->cert->chain_store; else chain_store = s->ctx->cert_store; if (chain_store != NULL) { X509_STORE_CTX *xs_ctx = X509_STORE_CTX_new(); if (xs_ctx == NULL) { SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, ERR_R_MALLOC_FAILURE); goto err; } if (!X509_STORE_CTX_init(xs_ctx, chain_store, x, NULL)) { X509_STORE_CTX_free(xs_ctx); SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, ERR_R_X509_LIB); goto err; } (void)X509_verify_cert(xs_ctx); ERR_clear_error(); chain = X509_STORE_CTX_get0_chain(xs_ctx); i = ssl_security_cert_chain(s, chain, NULL, 0); if (i != 1) { #if 0 SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, SSL_R_EE_KEY_TOO_SMALL); SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, SSL_R_CA_KEY_TOO_SMALL); SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, SSL_R_CA_MD_TOO_WEAK); #endif X509_STORE_CTX_free(xs_ctx); SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, i); goto err; } chain_count = sk_X509_num(chain); for (i = 0; i < chain_count; i++) { x = sk_X509_value(chain, i); if (!ssl_add_cert_to_wpacket(s, pkt, x, i, &tmpal)) { X509_STORE_CTX_free(xs_ctx); goto err; } } X509_STORE_CTX_free(xs_ctx); } else { i = ssl_security_cert_chain(s, extra_certs, x, 0); if (i != 1) { SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, i); goto err; } if (!ssl_add_cert_to_wpacket(s, pkt, x, 0, &tmpal)) goto err; for (i = 0; i < sk_X509_num(extra_certs); i++) { x = sk_X509_value(extra_certs, i); if (!ssl_add_cert_to_wpacket(s, pkt, x, i + 1, &tmpal)) goto err; } } return 1; err: *al = tmpal; return 0; }
['static int ssl_add_cert_chain(SSL *s, WPACKET *pkt, CERT_PKEY *cpk, int *al)\n{\n int i, chain_count;\n X509 *x;\n STACK_OF(X509) *extra_certs;\n STACK_OF(X509) *chain = NULL;\n X509_STORE *chain_store;\n int tmpal = SSL_AD_INTERNAL_ERROR;\n if (cpk == NULL || cpk->x509 == NULL)\n return 1;\n x = cpk->x509;\n if (cpk->chain != NULL)\n extra_certs = cpk->chain;\n else\n extra_certs = s->ctx->extra_certs;\n if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || extra_certs)\n chain_store = NULL;\n else if (s->cert->chain_store)\n chain_store = s->cert->chain_store;\n else\n chain_store = s->ctx->cert_store;\n if (chain_store != NULL) {\n X509_STORE_CTX *xs_ctx = X509_STORE_CTX_new();\n if (xs_ctx == NULL) {\n SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (!X509_STORE_CTX_init(xs_ctx, chain_store, x, NULL)) {\n X509_STORE_CTX_free(xs_ctx);\n SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, ERR_R_X509_LIB);\n goto err;\n }\n (void)X509_verify_cert(xs_ctx);\n ERR_clear_error();\n chain = X509_STORE_CTX_get0_chain(xs_ctx);\n i = ssl_security_cert_chain(s, chain, NULL, 0);\n if (i != 1) {\n#if 0\n SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, SSL_R_EE_KEY_TOO_SMALL);\n SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, SSL_R_CA_KEY_TOO_SMALL);\n SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, SSL_R_CA_MD_TOO_WEAK);\n#endif\n X509_STORE_CTX_free(xs_ctx);\n SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, i);\n goto err;\n }\n chain_count = sk_X509_num(chain);\n for (i = 0; i < chain_count; i++) {\n x = sk_X509_value(chain, i);\n if (!ssl_add_cert_to_wpacket(s, pkt, x, i, &tmpal)) {\n X509_STORE_CTX_free(xs_ctx);\n goto err;\n }\n }\n X509_STORE_CTX_free(xs_ctx);\n } else {\n i = ssl_security_cert_chain(s, extra_certs, x, 0);\n if (i != 1) {\n SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, i);\n goto err;\n }\n if (!ssl_add_cert_to_wpacket(s, pkt, x, 0, &tmpal))\n goto err;\n for (i = 0; i < sk_X509_num(extra_certs); i++) {\n x = sk_X509_value(extra_certs, i);\n if (!ssl_add_cert_to_wpacket(s, pkt, x, i + 1, &tmpal))\n goto err;\n }\n }\n return 1;\n err:\n *al = tmpal;\n return 0;\n}', 'X509_STORE_CTX *X509_STORE_CTX_new(void)\n{\n X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));\n if (ctx == NULL) {\n X509err(X509_F_X509_STORE_CTX_NEW, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n return ctx;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'void X509_STORE_CTX_free(X509_STORE_CTX *ctx)\n{\n if (ctx == NULL)\n return;\n X509_STORE_CTX_cleanup(ctx);\n OPENSSL_free(ctx);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
34,889
0
https://github.com/openssl/openssl/blob/33af4421f2ae5e4d0da3a121f51820f4b49a724c/crypto/bn/bn_ctx.c/#L440
static void BN_POOL_release(BN_POOL *p, unsigned int num) { unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE; p->used -= num; while(num--) { bn_check_top(p->current->vals + offset); if(!offset) { offset = BN_CTX_POOL_SIZE - 1; p->current = p->current->prev; } else offset--; } }
['int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx)\n\t{\n\tint ret = 0;\n\tBIGNUM *order;\n\tBN_CTX *new_ctx = NULL;\n\tEC_POINT *point = NULL;\n\tif (ctx == NULL)\n\t\t{\n\t\tctx = new_ctx = BN_CTX_new();\n\t\tif (ctx == NULL)\n\t\t\t{\n\t\t\tECerr(EC_F_EC_GROUP_CHECK, ERR_R_MALLOC_FAILURE);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tBN_CTX_start(ctx);\n\tif ((order = BN_CTX_get(ctx)) == NULL) goto err;\n\tif (!EC_GROUP_check_discriminant(group, ctx))\n\t\t{\n\t\tECerr(EC_F_EC_GROUP_CHECK, EC_R_DISCRIMINANT_IS_ZERO);\n\t\tgoto err;\n\t\t}\n\tif (group->generator == NULL)\n\t\t{\n\t\tECerr(EC_F_EC_GROUP_CHECK, EC_R_UNDEFINED_GENERATOR);\n\t\tgoto err;\n\t\t}\n\tif (!EC_POINT_is_on_curve(group, group->generator, ctx))\n\t\t{\n\t\tECerr(EC_F_EC_GROUP_CHECK, EC_R_POINT_IS_NOT_ON_CURVE);\n\t\tgoto err;\n\t\t}\n\tif ((point = EC_POINT_new(group)) == NULL) goto err;\n\tif (!EC_GROUP_get_order(group, order, ctx)) goto err;\n\tif (BN_is_zero(order))\n\t\t{\n\t\tECerr(EC_F_EC_GROUP_CHECK, EC_R_UNDEFINED_ORDER);\n\t\tgoto err;\n\t\t}\n\tif (!EC_POINT_mul(group, point, order, NULL, NULL, ctx)) goto err;\n\tif (!EC_POINT_is_at_infinity(group, point))\n\t\t{\n\t\tECerr(EC_F_EC_GROUP_CHECK, EC_R_INVALID_GROUP_ORDER);\n\t\tgoto err;\n\t\t}\n\tret = 1;\nerr:\n\tif (ctx != NULL)\n\t\tBN_CTX_end(ctx);\n\tif (new_ctx != NULL)\n\t\tBN_CTX_free(new_ctx);\n\tif (point)\n\t\tEC_POINT_free(point);\n\treturn ret;\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static void BN_POOL_release(BN_POOL *p, unsigned int num)\n\t{\n\tunsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;\n\tp->used -= num;\n\twhile(num--)\n\t\t{\n\t\tbn_check_top(p->current->vals + offset);\n\t\tif(!offset)\n\t\t\t{\n\t\t\toffset = BN_CTX_POOL_SIZE - 1;\n\t\t\tp->current = p->current->prev;\n\t\t\t}\n\t\telse\n\t\t\toffset--;\n\t\t}\n\t}']
34,890
0
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/h264pred.c/#L365
static void pred4x4_horizontal_up_rv40_c(uint8_t *src, uint8_t *topright, int stride){ LOAD_LEFT_EDGE LOAD_DOWN_LEFT_EDGE LOAD_TOP_EDGE LOAD_TOP_RIGHT_EDGE src[0+0*stride]=(t1 + 2*t2 + t3 + 2*l0 + 2*l1 + 4)>>3; src[1+0*stride]=(t2 + 2*t3 + t4 + l0 + 2*l1 + l2 + 4)>>3; src[2+0*stride]= src[0+1*stride]=(t3 + 2*t4 + t5 + 2*l1 + 2*l2 + 4)>>3; src[3+0*stride]= src[1+1*stride]=(t4 + 2*t5 + t6 + l1 + 2*l2 + l3 + 4)>>3; src[2+1*stride]= src[0+2*stride]=(t5 + 2*t6 + t7 + 2*l2 + 2*l3 + 4)>>3; src[3+1*stride]= src[1+2*stride]=(t6 + 3*t7 + l2 + 3*l3 + 4)>>3; src[3+2*stride]= src[1+3*stride]=(l3 + 2*l4 + l5 + 2)>>2; src[0+3*stride]= src[2+2*stride]=(t6 + t7 + l3 + l4 + 2)>>2; src[2+3*stride]=(l4 + l5 + 1)>>1; src[3+3*stride]=(l4 + 2*l5 + l6 + 2)>>2; }
['static void pred4x4_horizontal_up_rv40_c(uint8_t *src, uint8_t *topright, int stride){\n LOAD_LEFT_EDGE\n LOAD_DOWN_LEFT_EDGE\n LOAD_TOP_EDGE\n LOAD_TOP_RIGHT_EDGE\n src[0+0*stride]=(t1 + 2*t2 + t3 + 2*l0 + 2*l1 + 4)>>3;\n src[1+0*stride]=(t2 + 2*t3 + t4 + l0 + 2*l1 + l2 + 4)>>3;\n src[2+0*stride]=\n src[0+1*stride]=(t3 + 2*t4 + t5 + 2*l1 + 2*l2 + 4)>>3;\n src[3+0*stride]=\n src[1+1*stride]=(t4 + 2*t5 + t6 + l1 + 2*l2 + l3 + 4)>>3;\n src[2+1*stride]=\n src[0+2*stride]=(t5 + 2*t6 + t7 + 2*l2 + 2*l3 + 4)>>3;\n src[3+1*stride]=\n src[1+2*stride]=(t6 + 3*t7 + l2 + 3*l3 + 4)>>3;\n src[3+2*stride]=\n src[1+3*stride]=(l3 + 2*l4 + l5 + 2)>>2;\n src[0+3*stride]=\n src[2+2*stride]=(t6 + t7 + l3 + l4 + 2)>>2;\n src[2+3*stride]=(l4 + l5 + 1)>>1;\n src[3+3*stride]=(l4 + 2*l5 + l6 + 2)>>2;\n}']
34,891
0
https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bn/bn_lib.c/#L260
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words) { BN_ULONG *a = NULL; bn_check_top(b); if (words > (INT_MAX / (4 * BN_BITS2))) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG); return NULL; } if (BN_get_flags(b, BN_FLG_STATIC_DATA)) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); return NULL; } if (BN_get_flags(b, BN_FLG_SECURE)) a = OPENSSL_secure_zalloc(words * sizeof(*a)); else a = OPENSSL_zalloc(words * sizeof(*a)); if (a == NULL) { BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE); return NULL; } assert(b->top <= words); if (b->top > 0) memcpy(a, b->d, sizeof(*a) * b->top); return a; }
['int ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r,\n const BIGNUM *scalar, size_t num,\n const EC_POINT *points[], const BIGNUM *scalars[],\n BN_CTX *ctx)\n{\n BN_CTX *new_ctx = NULL;\n int ret = 0;\n size_t i;\n EC_POINT *p = NULL;\n EC_POINT *acc = NULL;\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return 0;\n }\n if ((scalar && (num > 1)) || (num > 2)\n || (num == 0 && EC_GROUP_have_precompute_mult(group))) {\n ret = ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);\n goto err;\n }\n if ((p = EC_POINT_new(group)) == NULL)\n goto err;\n if ((acc = EC_POINT_new(group)) == NULL)\n goto err;\n if (!EC_POINT_set_to_infinity(group, acc))\n goto err;\n if (scalar) {\n if (!ec_GF2m_montgomery_point_multiply\n (group, p, scalar, group->generator, ctx))\n goto err;\n if (BN_is_negative(scalar))\n if (!group->meth->invert(group, p, ctx))\n goto err;\n if (!group->meth->add(group, acc, acc, p, ctx))\n goto err;\n }\n for (i = 0; i < num; i++) {\n if (!ec_GF2m_montgomery_point_multiply\n (group, p, scalars[i], points[i], ctx))\n goto err;\n if (BN_is_negative(scalars[i]))\n if (!group->meth->invert(group, p, ctx))\n goto err;\n if (!group->meth->add(group, acc, acc, p, ctx))\n goto err;\n }\n if (!EC_POINT_copy(r, acc))\n goto err;\n ret = 1;\n err:\n EC_POINT_free(p);\n EC_POINT_free(acc);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'static int ec_GF2m_montgomery_point_multiply(const EC_GROUP *group,\n EC_POINT *r,\n const BIGNUM *scalar,\n const EC_POINT *point,\n BN_CTX *ctx)\n{\n BIGNUM *x1, *x2, *z1, *z2;\n int ret = 0, i, group_top;\n BN_ULONG mask, word;\n if (r == point) {\n ECerr(EC_F_EC_GF2M_MONTGOMERY_POINT_MULTIPLY, EC_R_INVALID_ARGUMENT);\n return 0;\n }\n if ((scalar == NULL) || BN_is_zero(scalar) || (point == NULL) ||\n EC_POINT_is_at_infinity(group, point)) {\n return EC_POINT_set_to_infinity(group, r);\n }\n if (!point->Z_is_one)\n return 0;\n BN_CTX_start(ctx);\n x1 = BN_CTX_get(ctx);\n z1 = BN_CTX_get(ctx);\n if (z1 == NULL)\n goto err;\n x2 = r->X;\n z2 = r->Y;\n group_top = bn_get_top(group->field);\n if (bn_wexpand(x1, group_top) == NULL\n || bn_wexpand(z1, group_top) == NULL\n || bn_wexpand(x2, group_top) == NULL\n || bn_wexpand(z2, group_top) == NULL)\n goto err;\n if (!BN_GF2m_mod_arr(x1, point->X, group->poly))\n goto err;\n if (!BN_one(z1))\n goto err;\n if (!group->meth->field_sqr(group, z2, x1, ctx))\n goto err;\n if (!group->meth->field_sqr(group, x2, z2, ctx))\n goto err;\n if (!BN_GF2m_add(x2, x2, group->b))\n goto err;\n i = bn_get_top(scalar) - 1;\n mask = BN_TBIT;\n word = bn_get_words(scalar)[i];\n while (!(word & mask))\n mask >>= 1;\n mask >>= 1;\n if (!mask) {\n i--;\n mask = BN_TBIT;\n }\n for (; i >= 0; i--) {\n word = bn_get_words(scalar)[i];\n while (mask) {\n BN_consttime_swap(word & mask, x1, x2, group_top);\n BN_consttime_swap(word & mask, z1, z2, group_top);\n if (!gf2m_Madd(group, point->X, x2, z2, x1, z1, ctx))\n goto err;\n if (!gf2m_Mdouble(group, x1, z1, ctx))\n goto err;\n BN_consttime_swap(word & mask, x1, x2, group_top);\n BN_consttime_swap(word & mask, z1, z2, group_top);\n mask >>= 1;\n }\n mask = BN_TBIT;\n }\n i = gf2m_Mxy(group, point->X, point->Y, x1, z1, x2, z2, ctx);\n if (i == 0)\n goto err;\n else if (i == 1) {\n if (!EC_POINT_set_to_infinity(group, r))\n goto err;\n } else {\n if (!BN_one(r->Z))\n goto err;\n r->Z_is_one = 1;\n }\n BN_set_negative(r->X, 0);\n BN_set_negative(r->Y, 0);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
34,892
0
https://gitlab.com/libtiff/libtiff/blob/bfbc717684115d7beb96c82255dad2dd4a4b8845/libtiff/tif_dirinfo.c/#L892
int TIFFMergeFieldInfo(TIFF* tif, const TIFFFieldInfo info[], uint32 n) { static const char module[] = "TIFFMergeFieldInfo"; static const char reason[] = "for fields array"; TIFFField *tp; size_t nfields; uint32 i; if (tif->tif_nfieldscompat > 0) { tif->tif_fieldscompat = (TIFFFieldArray *) _TIFFCheckRealloc(tif, tif->tif_fieldscompat, tif->tif_nfieldscompat + 1, sizeof(TIFFFieldArray), reason); } else { tif->tif_fieldscompat = (TIFFFieldArray *) _TIFFCheckMalloc(tif, 1, sizeof(TIFFFieldArray), reason); } if (!tif->tif_fieldscompat) { TIFFErrorExt(tif->tif_clientdata, module, "Failed to allocate fields array"); return -1; } nfields = tif->tif_nfieldscompat++; tif->tif_fieldscompat[nfields].type = tfiatOther; tif->tif_fieldscompat[nfields].allocated_size = n; tif->tif_fieldscompat[nfields].count = n; tif->tif_fieldscompat[nfields].fields = (TIFFField *)_TIFFCheckMalloc(tif, n, sizeof(TIFFField), reason); if (!tif->tif_fieldscompat[nfields].fields) { TIFFErrorExt(tif->tif_clientdata, module, "Failed to allocate fields array"); return -1; } tp = tif->tif_fieldscompat[nfields].fields; for (i = 0; i < n; i++) { tp->field_tag = info[i].field_tag; tp->field_readcount = info[i].field_readcount; tp->field_writecount = info[i].field_writecount; tp->field_type = info[i].field_type; tp->reserved = 0; tp->set_field_type = _TIFFSetGetType(info[i].field_type, info[i].field_readcount, info[i].field_passcount); tp->get_field_type = _TIFFSetGetType(info[i].field_type, info[i].field_readcount, info[i].field_passcount); tp->field_bit = info[i].field_bit; tp->field_oktochange = info[i].field_oktochange; tp->field_passcount = info[i].field_passcount; tp->field_name = info[i].field_name; tp->field_subfields = NULL; tp++; } if (!_TIFFMergeFields(tif, tif->tif_fieldscompat[nfields].fields, n)) { TIFFErrorExt(tif->tif_clientdata, module, "Setting up field info failed"); return -1; } return 0; }
['int\nTIFFMergeFieldInfo(TIFF* tif, const TIFFFieldInfo info[], uint32 n)\n{\n\tstatic const char module[] = "TIFFMergeFieldInfo";\n\tstatic const char reason[] = "for fields array";\n\tTIFFField *tp;\n\tsize_t nfields;\n\tuint32 i;\n\tif (tif->tif_nfieldscompat > 0) {\n\t\ttif->tif_fieldscompat = (TIFFFieldArray *)\n\t\t\t_TIFFCheckRealloc(tif, tif->tif_fieldscompat,\n\t\t\t\t\t tif->tif_nfieldscompat + 1,\n\t\t\t\t\t sizeof(TIFFFieldArray), reason);\n\t} else {\n\t\ttif->tif_fieldscompat = (TIFFFieldArray *)\n\t\t\t_TIFFCheckMalloc(tif, 1, sizeof(TIFFFieldArray),\n\t\t\t\t\t reason);\n\t}\n\tif (!tif->tif_fieldscompat) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t "Failed to allocate fields array");\n\t\treturn -1;\n\t}\n\tnfields = tif->tif_nfieldscompat++;\n\ttif->tif_fieldscompat[nfields].type = tfiatOther;\n\ttif->tif_fieldscompat[nfields].allocated_size = n;\n\ttif->tif_fieldscompat[nfields].count = n;\n\ttif->tif_fieldscompat[nfields].fields =\n\t\t(TIFFField *)_TIFFCheckMalloc(tif, n, sizeof(TIFFField),\n\t\t\t\t\t reason);\n\tif (!tif->tif_fieldscompat[nfields].fields) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t "Failed to allocate fields array");\n\t\treturn -1;\n\t}\n\ttp = tif->tif_fieldscompat[nfields].fields;\n\tfor (i = 0; i < n; i++) {\n\t\ttp->field_tag = info[i].field_tag;\n\t\ttp->field_readcount = info[i].field_readcount;\n\t\ttp->field_writecount = info[i].field_writecount;\n\t\ttp->field_type = info[i].field_type;\n\t\ttp->reserved = 0;\n\t\ttp->set_field_type =\n\t\t _TIFFSetGetType(info[i].field_type,\n\t\t\t\tinfo[i].field_readcount,\n\t\t\t\tinfo[i].field_passcount);\n\t\ttp->get_field_type =\n\t\t _TIFFSetGetType(info[i].field_type,\n\t\t\t\tinfo[i].field_readcount,\n\t\t\t\tinfo[i].field_passcount);\n\t\ttp->field_bit = info[i].field_bit;\n\t\ttp->field_oktochange = info[i].field_oktochange;\n\t\ttp->field_passcount = info[i].field_passcount;\n\t\ttp->field_name = info[i].field_name;\n\t\ttp->field_subfields = NULL;\n\t\ttp++;\n\t}\n\tif (!_TIFFMergeFields(tif, tif->tif_fieldscompat[nfields].fields, n)) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t "Setting up field info failed");\n\t\treturn -1;\n\t}\n\treturn 0;\n}', 'void*\n_TIFFCheckRealloc(TIFF* tif, void* buffer,\n\t\t tmsize_t nmemb, tmsize_t elem_size, const char* what)\n{\n\tvoid* cp = NULL;\n\ttmsize_t bytes = nmemb * elem_size;\n\tif (nmemb && elem_size && bytes / elem_size == nmemb)\n\t\tcp = _TIFFrealloc(buffer, bytes);\n\tif (cp == NULL)\n\t\tTIFFErrorExt(tif->tif_clientdata, tif->tif_name,\n\t\t\t "Failed to allocate memory for %s "\n\t\t\t "(%ld elements of %ld bytes each)",\n\t\t\t what,(long) nmemb, (long) elem_size);\n\treturn cp;\n}']
34,893
0
https://github.com/openssl/openssl/blob/e02c519cd32a55e6ad39a0cfbeeda775f9115f28/crypto/bn/bn_mul.c/#L46
BN_ULONG bn_sub_part_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int cl, int dl) { BN_ULONG c, t; assert(cl >= 0); c = bn_sub_words(r, a, b, cl); if (dl == 0) return c; r += cl; a += cl; b += cl; if (dl < 0) { for (;;) { t = b[0]; r[0] = (0 - t - c) & BN_MASK2; if (t != 0) c = 1; if (++dl >= 0) break; t = b[1]; r[1] = (0 - t - c) & BN_MASK2; if (t != 0) c = 1; if (++dl >= 0) break; t = b[2]; r[2] = (0 - t - c) & BN_MASK2; if (t != 0) c = 1; if (++dl >= 0) break; t = b[3]; r[3] = (0 - t - c) & BN_MASK2; if (t != 0) c = 1; if (++dl >= 0) break; b += 4; r += 4; } } else { int save_dl = dl; while (c) { t = a[0]; r[0] = (t - c) & BN_MASK2; if (t != 0) c = 0; if (--dl <= 0) break; t = a[1]; r[1] = (t - c) & BN_MASK2; if (t != 0) c = 0; if (--dl <= 0) break; t = a[2]; r[2] = (t - c) & BN_MASK2; if (t != 0) c = 0; if (--dl <= 0) break; t = a[3]; r[3] = (t - c) & BN_MASK2; if (t != 0) c = 0; if (--dl <= 0) break; save_dl = dl; a += 4; r += 4; } if (dl > 0) { if (save_dl > dl) { switch (save_dl - dl) { case 1: r[1] = a[1]; if (--dl <= 0) break; case 2: r[2] = a[2]; if (--dl <= 0) break; case 3: r[3] = a[3]; if (--dl <= 0) break; } a += 4; r += 4; } } if (dl > 0) { for (;;) { r[0] = a[0]; if (--dl <= 0) break; r[1] = a[1]; if (--dl <= 0) break; r[2] = a[2]; if (--dl <= 0) break; r[3] = a[3]; if (--dl <= 0) break; a += 4; r += 4; } } } return c; }
['int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,\n const BIGNUM *a2, const BIGNUM *p2, const BIGNUM *m,\n BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n int i, j, bits, b, bits1, bits2, ret =\n 0, wpos1, wpos2, window1, window2, wvalue1, wvalue2;\n int r_is_one = 1;\n BIGNUM *d, *r;\n const BIGNUM *a_mod_m;\n BIGNUM *val1[TABLE_SIZE], *val2[TABLE_SIZE];\n BN_MONT_CTX *mont = NULL;\n bn_check_top(a1);\n bn_check_top(p1);\n bn_check_top(a2);\n bn_check_top(p2);\n bn_check_top(m);\n if (!(m->d[0] & 1)) {\n BNerr(BN_F_BN_MOD_EXP2_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n bits1 = BN_num_bits(p1);\n bits2 = BN_num_bits(p2);\n if ((bits1 == 0) && (bits2 == 0)) {\n ret = BN_one(rr);\n return ret;\n }\n bits = (bits1 > bits2) ? bits1 : bits2;\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val1[0] = BN_CTX_get(ctx);\n val2[0] = BN_CTX_get(ctx);\n if (val2[0] == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n window1 = BN_window_bits_for_exponent_size(bits1);\n window2 = BN_window_bits_for_exponent_size(bits2);\n if (a1->neg || BN_ucmp(a1, m) >= 0) {\n if (!BN_mod(val1[0], a1, m, ctx))\n goto err;\n a_mod_m = val1[0];\n } else\n a_mod_m = a1;\n if (BN_is_zero(a_mod_m)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val1[0], a_mod_m, mont, ctx))\n goto err;\n if (window1 > 1) {\n if (!BN_mod_mul_montgomery(d, val1[0], val1[0], mont, ctx))\n goto err;\n j = 1 << (window1 - 1);\n for (i = 1; i < j; i++) {\n if (((val1[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val1[i], val1[i - 1], d, mont, ctx))\n goto err;\n }\n }\n if (a2->neg || BN_ucmp(a2, m) >= 0) {\n if (!BN_mod(val2[0], a2, m, ctx))\n goto err;\n a_mod_m = val2[0];\n } else\n a_mod_m = a2;\n if (BN_is_zero(a_mod_m)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val2[0], a_mod_m, mont, ctx))\n goto err;\n if (window2 > 1) {\n if (!BN_mod_mul_montgomery(d, val2[0], val2[0], mont, ctx))\n goto err;\n j = 1 << (window2 - 1);\n for (i = 1; i < j; i++) {\n if (((val2[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val2[i], val2[i - 1], d, mont, ctx))\n goto err;\n }\n }\n r_is_one = 1;\n wvalue1 = 0;\n wvalue2 = 0;\n wpos1 = 0;\n wpos2 = 0;\n if (!BN_to_montgomery(r, BN_value_one(), mont, ctx))\n goto err;\n for (b = bits - 1; b >= 0; b--) {\n if (!r_is_one) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (!wvalue1)\n if (BN_is_bit_set(p1, b)) {\n i = b - window1 + 1;\n while (!BN_is_bit_set(p1, i))\n i++;\n wpos1 = i;\n wvalue1 = 1;\n for (i = b - 1; i >= wpos1; i--) {\n wvalue1 <<= 1;\n if (BN_is_bit_set(p1, i))\n wvalue1++;\n }\n }\n if (!wvalue2)\n if (BN_is_bit_set(p2, b)) {\n i = b - window2 + 1;\n while (!BN_is_bit_set(p2, i))\n i++;\n wpos2 = i;\n wvalue2 = 1;\n for (i = b - 1; i >= wpos2; i--) {\n wvalue2 <<= 1;\n if (BN_is_bit_set(p2, i))\n wvalue2++;\n }\n }\n if (wvalue1 && b == wpos1) {\n if (!BN_mod_mul_montgomery(r, r, val1[wvalue1 >> 1], mont, ctx))\n goto err;\n wvalue1 = 0;\n r_is_one = 0;\n }\n if (wvalue2 && b == wpos2) {\n if (!BN_mod_mul_montgomery(r, r, val2[wvalue2 >> 1], mont, ctx))\n goto err;\n wvalue2 = 0;\n r_is_one = 0;\n }\n }\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'const BIGNUM *BN_value_one(void)\n{\n static const BN_ULONG data_one = 1L;\n static const BIGNUM const_one =\n { (BN_ULONG *)&data_one, 1, 1, 0, BN_FLG_STATIC_DATA };\n return &const_one;\n}', 'int BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n return BN_mod_mul_montgomery(r, a, &(mont->RR), mont, ctx);\n}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n int ret = bn_mul_mont_fixed_top(r, a, b, mont, ctx);\n bn_correct_top(r);\n bn_check_top(r);\n return ret;\n}', 'int bn_mul_mont_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n int num = mont->N.top;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return 0;\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n r->flags |= BN_FLG_FIXED_TOP;\n return 1;\n }\n }\n#endif\n if ((a->top + b->top) > 2 * num)\n return 0;\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!bn_sqr_fixed_top(tmp, a, ctx))\n goto err;\n } else {\n if (!bn_mul_fixed_top(tmp, a, b, ctx))\n goto err;\n }\n#ifdef MONT_WORD\n if (!bn_from_montgomery_word(r, tmp, mont))\n goto err;\n#else\n if (!BN_from_montgomery(r, tmp, mont, ctx))\n goto err;\n#endif\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int bn_mul_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return 1;\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n rr->flags |= BN_FLG_FIXED_TOP;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return ret;\n}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,\n int tna, int tnb, BN_ULONG *t)\n{\n int i, j, n2 = n * 2;\n int c1, c2, neg;\n BN_ULONG ln, lo, *p;\n if (n < 8) {\n bn_mul_normal(r, a, n + tna, b, n + tnb);\n return;\n }\n c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);\n c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);\n neg = 0;\n switch (c1 * 3 + c2) {\n case -4:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n break;\n case -3:\n case -2:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n neg = 1;\n break;\n case -1:\n case 0:\n case 1:\n case 2:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n neg = 1;\n break;\n case 3:\n case 4:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n break;\n }\n# if 0\n if (n == 4) {\n bn_mul_comba4(&(t[n2]), t, &(t[n]));\n bn_mul_comba4(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tn, &(b[n]), tn);\n memset(&r[n2 + tn * 2], 0, sizeof(*r) * (n2 - tn * 2));\n } else\n# endif\n if (n == 8) {\n bn_mul_comba8(&(t[n2]), t, &(t[n]));\n bn_mul_comba8(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n memset(&r[n2 + tna + tnb], 0, sizeof(*r) * (n2 - tna - tnb));\n } else {\n p = &(t[n2 * 2]);\n bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);\n bn_mul_recursive(r, a, b, n, 0, 0, p);\n i = n / 2;\n if (tna > tnb)\n j = tna - i;\n else\n j = tnb - i;\n if (j == 0) {\n bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&r[n2 + i * 2], 0, sizeof(*r) * (n2 - i * 2));\n } else if (j > 0) {\n bn_mul_part_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&(r[n2 + tna + tnb]), 0,\n sizeof(BN_ULONG) * (n2 - tna - tnb));\n } else {\n memset(&r[n2], 0, sizeof(*r) * n2);\n if (tna < BN_MUL_RECURSIVE_SIZE_NORMAL\n && tnb < BN_MUL_RECURSIVE_SIZE_NORMAL) {\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n } else {\n for (;;) {\n i /= 2;\n if (i < tna || i < tnb) {\n bn_mul_part_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n } else if (i == tna || i == tnb) {\n bn_mul_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n }\n }\n }\n }\n }\n c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));\n if (neg) {\n c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));\n } else {\n c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));\n }\n c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));\n if (c1) {\n p = &(r[n + n2]);\n lo = *p;\n ln = (lo + c1) & BN_MASK2;\n *p = ln;\n if (ln < (BN_ULONG)c1) {\n do {\n p++;\n lo = *p;\n ln = (lo + 1) & BN_MASK2;\n *p = ln;\n } while (ln == 0);\n }\n }\n}', 'int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b, int cl, int dl)\n{\n int n, i;\n n = cl - 1;\n if (dl < 0) {\n for (i = dl; i < 0; i++) {\n if (b[n - i] != 0)\n return -1;\n }\n }\n if (dl > 0) {\n for (i = dl; i > 0; i--) {\n if (a[n + i] != 0)\n return 1;\n }\n }\n return bn_cmp_words(a, b, cl);\n}', 'BN_ULONG bn_sub_part_words(BN_ULONG *r,\n const BN_ULONG *a, const BN_ULONG *b,\n int cl, int dl)\n{\n BN_ULONG c, t;\n assert(cl >= 0);\n c = bn_sub_words(r, a, b, cl);\n if (dl == 0)\n return c;\n r += cl;\n a += cl;\n b += cl;\n if (dl < 0) {\n for (;;) {\n t = b[0];\n r[0] = (0 - t - c) & BN_MASK2;\n if (t != 0)\n c = 1;\n if (++dl >= 0)\n break;\n t = b[1];\n r[1] = (0 - t - c) & BN_MASK2;\n if (t != 0)\n c = 1;\n if (++dl >= 0)\n break;\n t = b[2];\n r[2] = (0 - t - c) & BN_MASK2;\n if (t != 0)\n c = 1;\n if (++dl >= 0)\n break;\n t = b[3];\n r[3] = (0 - t - c) & BN_MASK2;\n if (t != 0)\n c = 1;\n if (++dl >= 0)\n break;\n b += 4;\n r += 4;\n }\n } else {\n int save_dl = dl;\n while (c) {\n t = a[0];\n r[0] = (t - c) & BN_MASK2;\n if (t != 0)\n c = 0;\n if (--dl <= 0)\n break;\n t = a[1];\n r[1] = (t - c) & BN_MASK2;\n if (t != 0)\n c = 0;\n if (--dl <= 0)\n break;\n t = a[2];\n r[2] = (t - c) & BN_MASK2;\n if (t != 0)\n c = 0;\n if (--dl <= 0)\n break;\n t = a[3];\n r[3] = (t - c) & BN_MASK2;\n if (t != 0)\n c = 0;\n if (--dl <= 0)\n break;\n save_dl = dl;\n a += 4;\n r += 4;\n }\n if (dl > 0) {\n if (save_dl > dl) {\n switch (save_dl - dl) {\n case 1:\n r[1] = a[1];\n if (--dl <= 0)\n break;\n case 2:\n r[2] = a[2];\n if (--dl <= 0)\n break;\n case 3:\n r[3] = a[3];\n if (--dl <= 0)\n break;\n }\n a += 4;\n r += 4;\n }\n }\n if (dl > 0) {\n for (;;) {\n r[0] = a[0];\n if (--dl <= 0)\n break;\n r[1] = a[1];\n if (--dl <= 0)\n break;\n r[2] = a[2];\n if (--dl <= 0)\n break;\n r[3] = a[3];\n if (--dl <= 0)\n break;\n a += 4;\n r += 4;\n }\n }\n }\n return c;\n}']
34,894
0
https://github.com/openssl/openssl/blob/fa3f83552f53447deced45579865cec9f55a947e/crypto/evp/evp_enc.c/#L290
int is_partially_overlapping(const void *ptr1, const void *ptr2, int len) { PTRDIFF_T diff = (PTRDIFF_T)ptr1-(PTRDIFF_T)ptr2; int overlapped = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) | (diff > (0 - (PTRDIFF_T)len))); return overlapped; }
['static int enc_read(BIO *b, char *out, int outl)\n{\n int ret = 0, i, blocksize;\n BIO_ENC_CTX *ctx;\n BIO *next;\n if (out == NULL)\n return (0);\n ctx = BIO_get_data(b);\n next = BIO_next(b);\n if ((ctx == NULL) || (next == NULL))\n return 0;\n if (ctx->buf_len > 0) {\n i = ctx->buf_len - ctx->buf_off;\n if (i > outl)\n i = outl;\n memcpy(out, &(ctx->buf[ctx->buf_off]), i);\n ret = i;\n out += i;\n outl -= i;\n ctx->buf_off += i;\n if (ctx->buf_len == ctx->buf_off) {\n ctx->buf_len = 0;\n ctx->buf_off = 0;\n }\n }\n blocksize = EVP_CIPHER_CTX_block_size(ctx->cipher);\n if (blocksize == 1)\n blocksize = 0;\n while (outl > 0) {\n if (ctx->cont <= 0)\n break;\n if (ctx->read_start == ctx->read_end) {\n ctx->read_end = ctx->read_start = &(ctx->buf[BUF_OFFSET]);\n i = BIO_read(next, ctx->read_start, ENC_BLOCK_SIZE);\n if (i > 0)\n ctx->read_end += i;\n } else {\n i = ctx->read_end - ctx->read_start;\n }\n if (i <= 0) {\n if (!BIO_should_retry(next)) {\n ctx->cont = i;\n i = EVP_CipherFinal_ex(ctx->cipher,\n ctx->buf, &(ctx->buf_len));\n ctx->ok = i;\n ctx->buf_off = 0;\n } else {\n ret = (ret == 0) ? i : ret;\n break;\n }\n } else {\n if (outl > ENC_MIN_CHUNK) {\n int j = outl - blocksize, buf_len;\n if (!EVP_CipherUpdate(ctx->cipher,\n (unsigned char *)out, &buf_len,\n ctx->read_start, i > j ? j : i)) {\n BIO_clear_retry_flags(b);\n return 0;\n }\n ret += buf_len;\n out += buf_len;\n outl -= buf_len;\n if ((i -= j) <= 0) {\n ctx->read_start = ctx->read_end;\n continue;\n }\n ctx->read_start += j;\n }\n if (i > ENC_MIN_CHUNK)\n i = ENC_MIN_CHUNK;\n if (!EVP_CipherUpdate(ctx->cipher,\n ctx->buf, &ctx->buf_len,\n ctx->read_start, i)) {\n BIO_clear_retry_flags(b);\n ctx->ok = 0;\n return 0;\n }\n ctx->read_start += i;\n ctx->cont = 1;\n if (ctx->buf_len == 0)\n continue;\n }\n if (ctx->buf_len <= outl)\n i = ctx->buf_len;\n else\n i = outl;\n if (i <= 0)\n break;\n memcpy(out, ctx->buf, i);\n ret += i;\n ctx->buf_off = i;\n outl -= i;\n out += i;\n }\n BIO_clear_retry_flags(b);\n BIO_copy_next_retry(b);\n return ((ret == 0) ? ctx->cont : ret);\n}', 'int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,\n const unsigned char *in, int inl)\n{\n if (ctx->encrypt)\n return EVP_EncryptUpdate(ctx, out, outl, in, inl);\n else\n return EVP_DecryptUpdate(ctx, out, outl, in, inl);\n}', 'int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,\n const unsigned char *in, int inl)\n{\n int fix_len, cmpl = inl;\n unsigned int b;\n b = ctx->cipher->block_size;\n if (EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS))\n cmpl = (cmpl + 7) / 8;\n if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {\n if (b == 1 && is_partially_overlapping(out, in, cmpl)) {\n EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);\n return 0;\n }\n fix_len = ctx->cipher->do_cipher(ctx, out, in, inl);\n if (fix_len < 0) {\n *outl = 0;\n return 0;\n } else\n *outl = fix_len;\n return 1;\n }\n if (inl <= 0) {\n *outl = 0;\n return inl == 0;\n }\n if (ctx->flags & EVP_CIPH_NO_PADDING)\n return EVP_EncryptUpdate(ctx, out, outl, in, inl);\n OPENSSL_assert(b <= sizeof ctx->final);\n if (ctx->final_used) {\n if (((PTRDIFF_T)out == (PTRDIFF_T)in)\n || is_partially_overlapping(out, in, b)) {\n EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);\n return 0;\n }\n memcpy(out, ctx->final, b);\n out += b;\n fix_len = 1;\n } else\n fix_len = 0;\n if (!EVP_EncryptUpdate(ctx, out, outl, in, inl))\n return 0;\n if (b > 1 && !ctx->buf_len) {\n *outl -= b;\n ctx->final_used = 1;\n memcpy(ctx->final, &out[*outl], b);\n } else\n ctx->final_used = 0;\n if (fix_len)\n *outl += b;\n return 1;\n}', 'int is_partially_overlapping(const void *ptr1, const void *ptr2, int len)\n{\n PTRDIFF_T diff = (PTRDIFF_T)ptr1-(PTRDIFF_T)ptr2;\n int overlapped = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) |\n (diff > (0 - (PTRDIFF_T)len)));\n return overlapped;\n}']
34,895
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/x509v3/pcy_tree.c/#L365
static int tree_add_unmatched(X509_POLICY_LEVEL *curr, const X509_POLICY_CACHE *cache, const ASN1_OBJECT *id, X509_POLICY_NODE *node, X509_POLICY_TREE *tree) { X509_POLICY_DATA *data; if (id == NULL) id = node->data->valid_policy; data = policy_data_new(NULL, id, node_critical(node)); if (data == NULL) return 0; data->qualifier_set = cache->anyPolicy->qualifier_set; data->flags |= POLICY_DATA_FLAG_SHARED_QUALIFIERS; if (!level_add_node(curr, data, node, tree)) { policy_data_free(data); return 0; } return 1; }
['static int tree_add_unmatched(X509_POLICY_LEVEL *curr,\n const X509_POLICY_CACHE *cache,\n const ASN1_OBJECT *id,\n X509_POLICY_NODE *node, X509_POLICY_TREE *tree)\n{\n X509_POLICY_DATA *data;\n if (id == NULL)\n id = node->data->valid_policy;\n data = policy_data_new(NULL, id, node_critical(node));\n if (data == NULL)\n return 0;\n data->qualifier_set = cache->anyPolicy->qualifier_set;\n data->flags |= POLICY_DATA_FLAG_SHARED_QUALIFIERS;\n if (!level_add_node(curr, data, node, tree)) {\n policy_data_free(data);\n return 0;\n }\n return 1;\n}', 'X509_POLICY_DATA *policy_data_new(POLICYINFO *policy,\n const ASN1_OBJECT *cid, int crit)\n{\n X509_POLICY_DATA *ret;\n ASN1_OBJECT *id;\n if (!policy && !cid)\n return NULL;\n if (cid) {\n id = OBJ_dup(cid);\n if (!id)\n return NULL;\n } else\n id = NULL;\n ret = OPENSSL_zalloc(sizeof(*ret));\n if (ret == NULL)\n return NULL;\n ret->expected_policy_set = sk_ASN1_OBJECT_new_null();\n if (ret->expected_policy_set == NULL) {\n OPENSSL_free(ret);\n ASN1_OBJECT_free(id);\n return NULL;\n }\n if (crit)\n ret->flags = POLICY_DATA_FLAG_CRITICAL;\n if (id)\n ret->valid_policy = id;\n else {\n ret->valid_policy = policy->policyid;\n policy->policyid = NULL;\n }\n if (policy) {\n ret->qualifier_set = policy->qualifiers;\n policy->qualifiers = NULL;\n }\n return ret;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifdef CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}', 'DEFINE_STACK_OF(ASN1_OBJECT)', '_STACK *sk_new_null(void)\n{\n return sk_new((int (*)(const void *, const void *))0);\n}', '_STACK *sk_new(int (*c) (const void *, const void *))\n{\n _STACK *ret;\n if ((ret = OPENSSL_zalloc(sizeof(_STACK))) == NULL)\n goto err;\n if ((ret->data = OPENSSL_zalloc(sizeof(*ret->data) * MIN_NODES)) == NULL)\n goto err;\n ret->comp = c;\n ret->num_alloc = MIN_NODES;\n return (ret);\n err:\n OPENSSL_free(ret);\n return (NULL);\n}']
34,896
0
https://github.com/libav/libav/blob/32a15a2441c4bfc83b2934f617d64d196492bdde/libavformat/utils.c/#L2469
void av_close_input_stream(AVFormatContext *s) { int i; AVStream *st; if (s->iformat->read_close) s->iformat->read_close(s); for(i=0;i<s->nb_streams;i++) { st = s->streams[i]; if (st->parser) { av_parser_close(st->parser); av_free_packet(&st->cur_pkt); } av_metadata_free(&st->metadata); av_free(st->index_entries); av_free(st->codec->extradata); av_free(st->codec); #if LAVF_API_OLD_METADATA av_free(st->filename); #endif av_free(st->priv_data); av_free(st); } for(i=s->nb_programs-1; i>=0; i--) { #if LAVF_API_OLD_METADATA av_freep(&s->programs[i]->provider_name); av_freep(&s->programs[i]->name); #endif av_metadata_free(&s->programs[i]->metadata); av_freep(&s->programs[i]->stream_index); av_freep(&s->programs[i]); } av_freep(&s->programs); flush_packet_queue(s); av_freep(&s->priv_data); while(s->nb_chapters--) { #if LAVF_API_OLD_METADATA av_free(s->chapters[s->nb_chapters]->title); #endif av_metadata_free(&s->chapters[s->nb_chapters]->metadata); av_free(s->chapters[s->nb_chapters]); } av_freep(&s->chapters); av_metadata_free(&s->metadata); av_free(s); }
['static int ffmpeg_exit(int ret)\n{\n int i;\n for(i=0;i<nb_output_files;i++) {\n AVFormatContext *s = output_files[i];\n int j;\n if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)\n url_fclose(s->pb);\n for(j=0;j<s->nb_streams;j++) {\n av_metadata_free(&s->streams[j]->metadata);\n av_free(s->streams[j]->codec);\n av_free(s->streams[j]);\n }\n for(j=0;j<s->nb_programs;j++) {\n av_metadata_free(&s->programs[j]->metadata);\n }\n for(j=0;j<s->nb_chapters;j++) {\n av_metadata_free(&s->chapters[j]->metadata);\n }\n av_metadata_free(&s->metadata);\n av_free(s);\n }\n for(i=0;i<nb_input_files;i++)\n av_close_input_file(input_files[i]);\n av_free(intra_matrix);\n av_free(inter_matrix);\n if (vstats_file)\n fclose(vstats_file);\n av_free(vstats_filename);\n av_free(opt_names);\n av_free(video_codec_name);\n av_free(audio_codec_name);\n av_free(subtitle_codec_name);\n av_free(video_standard);\n for (i=0;i<AVMEDIA_TYPE_NB;i++)\n av_free(avcodec_opts[i]);\n av_free(avformat_opts);\n av_free(sws_opts);\n av_free(audio_buf);\n av_free(audio_out);\n allocated_audio_buf_size= allocated_audio_out_size= 0;\n av_free(samples);\n#if CONFIG_AVFILTER\n avfilter_uninit();\n#endif\n if (received_sigterm) {\n fprintf(stderr,\n "Received signal %d: terminating.\\n",\n (int) received_sigterm);\n exit (255);\n }\n exit(ret);\n return ret;\n}', 'void av_close_input_file(AVFormatContext *s)\n{\n ByteIOContext *pb = s->iformat->flags & AVFMT_NOFILE ? NULL : s->pb;\n av_close_input_stream(s);\n if (pb)\n url_fclose(pb);\n}', 'void av_close_input_stream(AVFormatContext *s)\n{\n int i;\n AVStream *st;\n if (s->iformat->read_close)\n s->iformat->read_close(s);\n for(i=0;i<s->nb_streams;i++) {\n st = s->streams[i];\n if (st->parser) {\n av_parser_close(st->parser);\n av_free_packet(&st->cur_pkt);\n }\n av_metadata_free(&st->metadata);\n av_free(st->index_entries);\n av_free(st->codec->extradata);\n av_free(st->codec);\n#if LAVF_API_OLD_METADATA\n av_free(st->filename);\n#endif\n av_free(st->priv_data);\n av_free(st);\n }\n for(i=s->nb_programs-1; i>=0; i--) {\n#if LAVF_API_OLD_METADATA\n av_freep(&s->programs[i]->provider_name);\n av_freep(&s->programs[i]->name);\n#endif\n av_metadata_free(&s->programs[i]->metadata);\n av_freep(&s->programs[i]->stream_index);\n av_freep(&s->programs[i]);\n }\n av_freep(&s->programs);\n flush_packet_queue(s);\n av_freep(&s->priv_data);\n while(s->nb_chapters--) {\n#if LAVF_API_OLD_METADATA\n av_free(s->chapters[s->nb_chapters]->title);\n#endif\n av_metadata_free(&s->chapters[s->nb_chapters]->metadata);\n av_free(s->chapters[s->nb_chapters]);\n }\n av_freep(&s->chapters);\n av_metadata_free(&s->metadata);\n av_free(s);\n}']
34,897
0
https://github.com/openssl/openssl/blob/8ae173bb57819a23717fd3c8e7c51cb62f4268d0/crypto/bn/bn_ctx.c/#L300
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits,\n const EVP_MD *evpmd, const unsigned char *seed_in,\n size_t seed_len, unsigned char *seed_out,\n int *counter_ret, unsigned long *h_ret, BN_GENCB *cb)\n{\n int ok = 0;\n unsigned char seed[SHA256_DIGEST_LENGTH];\n unsigned char md[SHA256_DIGEST_LENGTH];\n unsigned char buf[SHA256_DIGEST_LENGTH], buf2[SHA256_DIGEST_LENGTH];\n BIGNUM *r0, *W, *X, *c, *test;\n BIGNUM *g = NULL, *q = NULL, *p = NULL;\n BN_MONT_CTX *mont = NULL;\n int i, k, n = 0, m = 0, qsize = qbits >> 3;\n int counter = 0;\n int r = 0;\n BN_CTX *ctx = NULL;\n unsigned int h = 2;\n if (qsize != SHA_DIGEST_LENGTH && qsize != SHA224_DIGEST_LENGTH &&\n qsize != SHA256_DIGEST_LENGTH)\n return 0;\n if (evpmd == NULL) {\n if (qsize == SHA_DIGEST_LENGTH)\n evpmd = EVP_sha1();\n else if (qsize == SHA224_DIGEST_LENGTH)\n evpmd = EVP_sha224();\n else\n evpmd = EVP_sha256();\n } else {\n qsize = EVP_MD_size(evpmd);\n }\n if (bits < 512)\n bits = 512;\n bits = (bits + 63) / 64 * 64;\n if (seed_in != NULL) {\n if (seed_len < (size_t)qsize) {\n DSAerr(DSA_F_DSA_BUILTIN_PARAMGEN, DSA_R_SEED_LEN_SMALL);\n return 0;\n }\n if (seed_len > (size_t)qsize) {\n seed_len = qsize;\n }\n memcpy(seed, seed_in, seed_len);\n }\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n BN_CTX_start(ctx);\n r0 = BN_CTX_get(ctx);\n g = BN_CTX_get(ctx);\n W = BN_CTX_get(ctx);\n q = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n c = BN_CTX_get(ctx);\n p = BN_CTX_get(ctx);\n test = BN_CTX_get(ctx);\n if (test == NULL)\n goto err;\n if (!BN_lshift(test, BN_value_one(), bits - 1))\n goto err;\n for (;;) {\n for (;;) {\n int use_random_seed = (seed_in == NULL);\n if (!BN_GENCB_call(cb, 0, m++))\n goto err;\n if (use_random_seed) {\n if (RAND_bytes(seed, qsize) <= 0)\n goto err;\n } else {\n seed_in = NULL;\n }\n memcpy(buf, seed, qsize);\n memcpy(buf2, seed, qsize);\n for (i = qsize - 1; i >= 0; i--) {\n buf[i]++;\n if (buf[i] != 0)\n break;\n }\n if (!EVP_Digest(seed, qsize, md, NULL, evpmd, NULL))\n goto err;\n if (!EVP_Digest(buf, qsize, buf2, NULL, evpmd, NULL))\n goto err;\n for (i = 0; i < qsize; i++)\n md[i] ^= buf2[i];\n md[0] |= 0x80;\n md[qsize - 1] |= 0x01;\n if (!BN_bin2bn(md, qsize, q))\n goto err;\n r = BN_is_prime_fasttest_ex(q, DSS_prime_checks, ctx,\n use_random_seed, cb);\n if (r > 0)\n break;\n if (r != 0)\n goto err;\n }\n if (!BN_GENCB_call(cb, 2, 0))\n goto err;\n if (!BN_GENCB_call(cb, 3, 0))\n goto err;\n counter = 0;\n n = (bits - 1) / 160;\n for (;;) {\n if ((counter != 0) && !BN_GENCB_call(cb, 0, counter))\n goto err;\n BN_zero(W);\n for (k = 0; k <= n; k++) {\n for (i = qsize - 1; i >= 0; i--) {\n buf[i]++;\n if (buf[i] != 0)\n break;\n }\n if (!EVP_Digest(buf, qsize, md, NULL, evpmd, NULL))\n goto err;\n if (!BN_bin2bn(md, qsize, r0))\n goto err;\n if (!BN_lshift(r0, r0, (qsize << 3) * k))\n goto err;\n if (!BN_add(W, W, r0))\n goto err;\n }\n if (!BN_mask_bits(W, bits - 1))\n goto err;\n if (!BN_copy(X, W))\n goto err;\n if (!BN_add(X, X, test))\n goto err;\n if (!BN_lshift1(r0, q))\n goto err;\n if (!BN_mod(c, X, r0, ctx))\n goto err;\n if (!BN_sub(r0, c, BN_value_one()))\n goto err;\n if (!BN_sub(p, X, r0))\n goto err;\n if (BN_cmp(p, test) >= 0) {\n r = BN_is_prime_fasttest_ex(p, DSS_prime_checks, ctx, 1, cb);\n if (r > 0)\n goto end;\n if (r != 0)\n goto err;\n }\n counter++;\n if (counter >= 4096)\n break;\n }\n }\n end:\n if (!BN_GENCB_call(cb, 2, 1))\n goto err;\n if (!BN_sub(test, p, BN_value_one()))\n goto err;\n if (!BN_div(r0, NULL, test, q, ctx))\n goto err;\n if (!BN_set_word(test, h))\n goto err;\n if (!BN_MONT_CTX_set(mont, p, ctx))\n goto err;\n for (;;) {\n if (!BN_mod_exp_mont(g, test, r0, p, ctx, mont))\n goto err;\n if (!BN_is_one(g))\n break;\n if (!BN_add(test, test, BN_value_one()))\n goto err;\n h++;\n }\n if (!BN_GENCB_call(cb, 3, 1))\n goto err;\n ok = 1;\n err:\n if (ok) {\n BN_free(ret->p);\n BN_free(ret->q);\n BN_free(ret->g);\n ret->p = BN_dup(p);\n ret->q = BN_dup(q);\n ret->g = BN_dup(g);\n if (ret->p == NULL || ret->q == NULL || ret->g == NULL) {\n ok = 0;\n goto err;\n }\n if (counter_ret != NULL)\n *counter_ret = counter;\n if (h_ret != NULL)\n *h_ret = h;\n if (seed_out)\n memcpy(seed_out, seed, qsize);\n }\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n BN_MONT_CTX_free(mont);\n return ok;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_start()", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', 'int BN_is_prime_fasttest_ex(const BIGNUM *w, int checks, BN_CTX *ctx,\n int do_trial_division, BN_GENCB *cb)\n{\n int i, status, ret = -1;\n#ifndef FIPS_MODE\n BN_CTX *ctxlocal = NULL;\n#else\n if (ctx == NULL)\n return -1;\n#endif\n if (BN_cmp(w, BN_value_one()) <= 0)\n return 0;\n if (BN_is_odd(w)) {\n if (BN_is_word(w, 3))\n return 1;\n } else {\n return BN_is_word(w, 2);\n }\n if (do_trial_division) {\n for (i = 1; i < NUMPRIMES; i++) {\n BN_ULONG mod = BN_mod_word(w, primes[i]);\n if (mod == (BN_ULONG)-1)\n return -1;\n if (mod == 0)\n return BN_is_word(w, primes[i]);\n }\n if (!BN_GENCB_call(cb, 1, -1))\n return -1;\n }\n#ifndef FIPS_MODE\n if (ctx == NULL && (ctxlocal = ctx = BN_CTX_new()) == NULL)\n goto err;\n#endif\n ret = bn_miller_rabin_is_prime(w, checks, ctx, cb, 0, &status);\n if (!ret)\n goto err;\n ret = (status == BN_PRIMETEST_PROBABLY_PRIME);\nerr:\n#ifndef FIPS_MODE\n BN_CTX_free(ctxlocal);\n#endif\n return ret;\n}', 'int bn_miller_rabin_is_prime(const BIGNUM *w, int iterations, BN_CTX *ctx,\n BN_GENCB *cb, int enhanced, int *status)\n{\n int i, j, a, ret = 0;\n BIGNUM *g, *w1, *w3, *x, *m, *z, *b;\n BN_MONT_CTX *mont = NULL;\n if (!BN_is_odd(w))\n return 0;\n BN_CTX_start(ctx);\n g = BN_CTX_get(ctx);\n w1 = BN_CTX_get(ctx);\n w3 = BN_CTX_get(ctx);\n x = BN_CTX_get(ctx);\n m = BN_CTX_get(ctx);\n z = BN_CTX_get(ctx);\n b = BN_CTX_get(ctx);\n if (!(b != NULL\n && BN_copy(w1, w)\n && BN_sub_word(w1, 1)\n && BN_copy(w3, w)\n && BN_sub_word(w3, 3)))\n goto err;\n if (BN_is_zero(w3) || BN_is_negative(w3))\n goto err;\n a = 1;\n while (!BN_is_bit_set(w1, a))\n a++;\n if (!BN_rshift(m, w1, a))\n goto err;\n mont = BN_MONT_CTX_new();\n if (mont == NULL || !BN_MONT_CTX_set(mont, w, ctx))\n goto err;\n if (iterations == BN_prime_checks)\n iterations = BN_prime_checks_for_size(BN_num_bits(w));\n for (i = 0; i < iterations; ++i) {\n if (!BN_priv_rand_range_ex(b, w3, ctx)\n || !BN_add_word(b, 2))\n goto err;\n if (enhanced) {\n if (!BN_gcd(g, b, w, ctx))\n goto err;\n if (!BN_is_one(g)) {\n *status = BN_PRIMETEST_COMPOSITE_WITH_FACTOR;\n ret = 1;\n goto err;\n }\n }\n if (!BN_mod_exp_mont(z, b, m, w, ctx, mont))\n goto err;\n if (BN_is_one(z) || BN_cmp(z, w1) == 0)\n goto outer_loop;\n for (j = 1; j < a ; ++j) {\n if (!BN_copy(x, z) || !BN_mod_mul(z, x, x, w, ctx))\n goto err;\n if (BN_cmp(z, w1) == 0)\n goto outer_loop;\n if (BN_is_one(z))\n goto composite;\n }\n if (!BN_copy(x, z) || !BN_mod_mul(z, x, x, w, ctx))\n goto err;\n if (BN_is_one(z))\n goto composite;\n if (!BN_copy(x, z))\n goto err;\ncomposite:\n if (enhanced) {\n if (!BN_sub_word(x, 1) || !BN_gcd(g, x, w, ctx))\n goto err;\n if (BN_is_one(g))\n *status = BN_PRIMETEST_COMPOSITE_NOT_POWER_OF_PRIME;\n else\n *status = BN_PRIMETEST_COMPOSITE_WITH_FACTOR;\n } else {\n *status = BN_PRIMETEST_COMPOSITE;\n }\n ret = 1;\n goto err;\nouter_loop: ;\n if (!BN_GENCB_call(cb, 1, i))\n goto err;\n }\n *status = BN_PRIMETEST_PROBABLY_PRIME;\n ret = 1;\nerr:\n BN_clear(g);\n BN_clear(w1);\n BN_clear(w3);\n BN_clear(x);\n BN_clear(m);\n BN_clear(z);\n BN_clear(b);\n BN_CTX_end(ctx);\n BN_MONT_CTX_free(mont);\n return ret;\n}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n{\n int i, ret = 0;\n BIGNUM *Ri, *R;\n if (BN_is_zero(mod))\n return 0;\n BN_CTX_start(ctx);\n if ((Ri = BN_CTX_get(ctx)) == NULL)\n goto err;\n R = &(mont->RR);\n if (!BN_copy(&(mont->N), mod))\n goto err;\n if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(&(mont->N), BN_FLG_CONSTTIME);\n mont->N.neg = 0;\n#ifdef MONT_WORD\n {\n BIGNUM tmod;\n BN_ULONG buf[2];\n bn_init(&tmod);\n tmod.d = buf;\n tmod.dmax = 2;\n tmod.neg = 0;\n if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(&tmod, BN_FLG_CONSTTIME);\n mont->ri = (BN_num_bits(mod) + (BN_BITS2 - 1)) / BN_BITS2 * BN_BITS2;\n# if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n BN_zero(R);\n if (!(BN_set_bit(R, 2 * BN_BITS2)))\n goto err;\n tmod.top = 0;\n if ((buf[0] = mod->d[0]))\n tmod.top = 1;\n if ((buf[1] = mod->top > 1 ? mod->d[1] : 0))\n tmod.top = 2;\n if (BN_is_one(&tmod))\n BN_zero(Ri);\n else if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, 2 * BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (bn_expand(Ri, (int)sizeof(BN_ULONG) * 2) == NULL)\n goto err;\n Ri->neg = 0;\n Ri->d[0] = BN_MASK2;\n Ri->d[1] = BN_MASK2;\n Ri->top = 2;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n# else\n BN_zero(R);\n if (!(BN_set_bit(R, BN_BITS2)))\n goto err;\n buf[0] = mod->d[0];\n buf[1] = 0;\n tmod.top = buf[0] != 0 ? 1 : 0;\n if (BN_is_one(&tmod))\n BN_zero(Ri);\n else if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (!BN_set_word(Ri, BN_MASK2))\n goto err;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = 0;\n# endif\n }\n#else\n {\n mont->ri = BN_num_bits(&mont->N);\n BN_zero(R);\n if (!BN_set_bit(R, mont->ri))\n goto err;\n if ((BN_mod_inverse(Ri, R, &mont->N, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, mont->ri))\n goto err;\n if (!BN_sub_word(Ri, 1))\n goto err;\n if (!BN_div(&(mont->Ni), NULL, Ri, &mont->N, ctx))\n goto err;\n }\n#endif\n BN_zero(&(mont->RR));\n if (!BN_set_bit(&(mont->RR), mont->ri * 2))\n goto err;\n if (!BN_mod(&(mont->RR), &(mont->RR), &(mont->N), ctx))\n goto err;\n for (i = mont->RR.top, ret = mont->N.top; i < ret; i++)\n mont->RR.d[i] = 0;\n mont->RR.top = ret;\n mont->RR.flags |= BN_FLG_FIXED_TOP;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n{\n BIGNUM *rv;\n int noinv;\n rv = int_bn_mod_inverse(in, a, n, ctx, &noinv);\n if (noinv)\n BNerr(BN_F_BN_MOD_INVERSE, BN_R_NO_INVERSE);\n return rv;\n}', 'BIGNUM *int_bn_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx,\n int *pnoinv)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n if (BN_abs_is_word(n, 1) || BN_is_zero(n)) {\n if (pnoinv != NULL)\n *pnoinv = 1;\n return NULL;\n }\n if (pnoinv != NULL)\n *pnoinv = 0;\n if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0)) {\n return BN_mod_inverse_no_branch(in, a, n, ctx);\n }\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n if (!BN_nnmod(B, B, A, ctx))\n goto err;\n }\n sign = -1;\n if (BN_is_odd(n) && (BN_num_bits(n) <= 2048)) {\n int shift;\n while (!BN_is_zero(B)) {\n shift = 0;\n while (!BN_is_bit_set(B, shift)) {\n shift++;\n if (BN_is_odd(X)) {\n if (!BN_uadd(X, X, n))\n goto err;\n }\n if (!BN_rshift1(X, X))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(B, B, shift))\n goto err;\n }\n shift = 0;\n while (!BN_is_bit_set(A, shift)) {\n shift++;\n if (BN_is_odd(Y)) {\n if (!BN_uadd(Y, Y, n))\n goto err;\n }\n if (!BN_rshift1(Y, Y))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(A, A, shift))\n goto err;\n }\n if (BN_ucmp(B, A) >= 0) {\n if (!BN_uadd(X, X, Y))\n goto err;\n if (!BN_usub(B, B, A))\n goto err;\n } else {\n if (!BN_uadd(Y, Y, X))\n goto err;\n if (!BN_usub(A, A, B))\n goto err;\n }\n }\n } else {\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n if (BN_num_bits(A) == BN_num_bits(B)) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else if (BN_num_bits(A) == BN_num_bits(B) + 1) {\n if (!BN_lshift1(T, B))\n goto err;\n if (BN_ucmp(A, T) < 0) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else {\n if (!BN_sub(M, A, T))\n goto err;\n if (!BN_add(D, T, B))\n goto err;\n if (BN_ucmp(A, D) < 0) {\n if (!BN_set_word(D, 2))\n goto err;\n } else {\n if (!BN_set_word(D, 3))\n goto err;\n if (!BN_sub(M, M, B))\n goto err;\n }\n }\n } else {\n if (!BN_div(D, M, A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (BN_is_one(D)) {\n if (!BN_add(tmp, X, Y))\n goto err;\n } else {\n if (BN_is_word(D, 2)) {\n if (!BN_lshift1(tmp, X))\n goto err;\n } else if (BN_is_word(D, 4)) {\n if (!BN_lshift(tmp, X, 2))\n goto err;\n } else if (D->top == 1) {\n if (!BN_copy(tmp, X))\n goto err;\n if (!BN_mul_word(tmp, D->d[0]))\n goto err;\n } else {\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n }\n if (!BN_add(tmp, tmp, Y))\n goto err;\n }\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n if (pnoinv)\n *pnoinv = 1;\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return ret;\n}', 'static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n,\n BN_CTX *ctx)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n {\n BIGNUM local_B;\n bn_init(&local_B);\n BN_with_flags(&local_B, B, BN_FLG_CONSTTIME);\n if (!BN_nnmod(B, &local_B, A, ctx))\n goto err;\n }\n }\n sign = -1;\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n {\n BIGNUM local_A;\n bn_init(&local_A);\n BN_with_flags(&local_A, A, BN_FLG_CONSTTIME);\n if (!BN_div(D, M, &local_A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n if (!BN_add(tmp, tmp, Y))\n goto err;\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n BNerr(BN_F_BN_MOD_INVERSE_NO_BRANCH, BN_R_NO_INVERSE);\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return ret;\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int ret;\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (divisor->d[divisor->top - 1] == 0) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n ret = bn_div_fixed_top(dv, rm, num, divisor, ctx);\n if (ret) {\n if (dv != NULL)\n bn_correct_top(dv);\n if (rm != NULL)\n bn_correct_top(rm);\n }\n return ret;\n}', 'int bn_div_fixed_top(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,\n const BIGNUM *divisor, BN_CTX *ctx)\n{\n int norm_shift, i, j, loop;\n BIGNUM *tmp, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnum, *wnumtop;\n BN_ULONG d0, d1;\n int num_n, div_n;\n assert(divisor->top > 0 && divisor->d[divisor->top - 1] != 0);\n bn_check_top(num);\n bn_check_top(divisor);\n bn_check_top(dv);\n bn_check_top(rm);\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n if (!BN_copy(sdiv, divisor))\n goto err;\n norm_shift = bn_left_align(sdiv);\n sdiv->neg = 0;\n if (!(bn_lshift_fixed_top(snum, num, norm_shift)))\n goto err;\n div_n = sdiv->top;\n num_n = snum->top;\n if (num_n <= div_n) {\n if (bn_wexpand(snum, div_n + 1) == NULL)\n goto err;\n memset(&(snum->d[num_n]), 0, (div_n - num_n + 1) * sizeof(BN_ULONG));\n snum->top = num_n = div_n + 1;\n }\n loop = num_n - div_n;\n wnum = &(snum->d[loop]);\n wnumtop = &(snum->d[num_n - 1]);\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n if (!bn_wexpand(res, loop))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop;\n res->flags |= BN_FLG_FIXED_TOP;\n resp = &(res->d[loop]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n for (i = 0; i < loop; i++, wnumtop--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W)\n q = bn_div_3_words(wnumtop, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnumtop[0];\n n1 = wnumtop[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n BN_ULONG n2 = (wnumtop == wnum) ? 0 : wnumtop[-2];\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | n2))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= n2)))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum--;\n l0 = bn_sub_words(wnum, wnum, tmp->d, div_n + 1);\n q -= l0;\n for (l0 = 0 - l0, j = 0; j < div_n; j++)\n tmp->d[j] = sdiv->d[j] & l0;\n l0 = bn_add_words(wnum, wnum, tmp->d, div_n);\n (*wnumtop) += l0;\n assert((*wnumtop) == 0);\n *--resp = q;\n }\n snum->neg = num->neg;\n snum->top = div_n;\n snum->flags |= BN_FLG_FIXED_TOP;\n if (rm != NULL)\n bn_rshift_fixed_top(rm, snum, norm_shift);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return 0;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n if (ctx == NULL)\n return;\n CTXDBG("ENTER BN_CTX_end()", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
34,898
0
https://github.com/libav/libav/blob/bb4afa13dd3264832bc379bbfefe1db8cf4f0e40/libavcodec/utils.c/#L56
void *av_fast_realloc(void *ptr, unsigned int *size, FF_INTERNALC_MEM_TYPE min_size) { if(min_size < *size) return ptr; min_size= FFMAX(17*min_size/16 + 32, min_size); ptr= av_realloc(ptr, min_size); if(!ptr) min_size= 0; *size= min_size; return ptr; }
['int av_add_index_entry(AVStream *st,\n int64_t pos, int64_t timestamp, int size, int distance, int flags)\n{\n AVIndexEntry *entries, *ie;\n int index;\n if((unsigned)st->nb_index_entries + 1 >= UINT_MAX / sizeof(AVIndexEntry))\n return -1;\n entries = av_fast_realloc(st->index_entries,\n &st->index_entries_allocated_size,\n (st->nb_index_entries + 1) *\n sizeof(AVIndexEntry));\n if(!entries)\n return -1;\n st->index_entries= entries;\n index= av_index_search_timestamp(st, timestamp, AVSEEK_FLAG_ANY);\n if(index<0){\n index= st->nb_index_entries++;\n ie= &entries[index];\n assert(index==0 || ie[-1].timestamp < timestamp);\n }else{\n ie= &entries[index];\n if(ie->timestamp != timestamp){\n if(ie->timestamp <= timestamp)\n return -1;\n memmove(entries + index + 1, entries + index, sizeof(AVIndexEntry)*(st->nb_index_entries - index));\n st->nb_index_entries++;\n }else if(ie->pos == pos && distance < ie->min_distance)\n distance= ie->min_distance;\n }\n ie->pos = pos;\n ie->timestamp = timestamp;\n ie->min_distance= distance;\n ie->size= size;\n ie->flags = flags;\n return index;\n}', 'void *av_fast_realloc(void *ptr, unsigned int *size, FF_INTERNALC_MEM_TYPE min_size)\n{\n if(min_size < *size)\n return ptr;\n min_size= FFMAX(17*min_size/16 + 32, min_size);\n ptr= av_realloc(ptr, min_size);\n if(!ptr)\n min_size= 0;\n *size= min_size;\n return ptr;\n}']
34,899
0
https://github.com/openssl/openssl/blob/c3fd55d4a6ed1025c471603b67fbbbce606a5171/crypto/evp/evp_enc.c/#L289
static int is_partially_overlapping(const void *ptr1, const void *ptr2, int len) { PTRDIFF_T diff = (PTRDIFF_T)ptr1-(PTRDIFF_T)ptr2; int condition = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) | (diff > (0 - (PTRDIFF_T)len))); assert(!condition); return condition; }
['static int kek_unwrap_key(unsigned char *out, size_t *outlen,\n const unsigned char *in, size_t inlen,\n EVP_CIPHER_CTX *ctx)\n{\n size_t blocklen = EVP_CIPHER_CTX_block_size(ctx);\n unsigned char *tmp;\n int outl, rv = 0;\n if (inlen < 2 * blocklen) {\n return 0;\n }\n if (inlen % blocklen) {\n return 0;\n }\n tmp = OPENSSL_malloc(inlen);\n if (tmp == NULL)\n return 0;\n if (!EVP_DecryptUpdate(ctx, tmp + inlen - 2 * blocklen, &outl,\n in + inlen - 2 * blocklen, blocklen * 2)\n || !EVP_DecryptUpdate(ctx, tmp, &outl,\n tmp + inlen - blocklen, blocklen)\n || !EVP_DecryptUpdate(ctx, tmp, &outl, in, inlen - blocklen)\n || !EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, NULL)\n || !EVP_DecryptUpdate(ctx, tmp, &outl, tmp, inlen))\n goto err;\n if (((tmp[1] ^ tmp[4]) & (tmp[2] ^ tmp[5]) & (tmp[3] ^ tmp[6])) != 0xff) {\n goto err;\n }\n if (inlen < (size_t)(tmp[0] - 4)) {\n goto err;\n }\n *outlen = (size_t)tmp[0];\n memcpy(out, tmp + 4, *outlen);\n rv = 1;\n err:\n OPENSSL_clear_free(tmp, inlen);\n return rv;\n}', 'int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,\n const unsigned char *in, int inl)\n{\n int fix_len;\n unsigned int b;\n if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {\n if (is_partially_overlapping(out, in, inl))\n return 0;\n fix_len = ctx->cipher->do_cipher(ctx, out, in, inl);\n if (fix_len < 0) {\n *outl = 0;\n return 0;\n } else\n *outl = fix_len;\n return 1;\n }\n if (inl <= 0) {\n *outl = 0;\n return inl == 0;\n }\n if (ctx->flags & EVP_CIPH_NO_PADDING)\n return EVP_EncryptUpdate(ctx, out, outl, in, inl);\n b = ctx->cipher->block_size;\n OPENSSL_assert(b <= sizeof ctx->final);\n if (ctx->final_used) {\n if (((PTRDIFF_T)out == (PTRDIFF_T)in)\n || is_partially_overlapping(out, in, b))\n return 0;\n memcpy(out, ctx->final, b);\n out += b;\n fix_len = 1;\n } else\n fix_len = 0;\n if (!EVP_EncryptUpdate(ctx, out, outl, in, inl))\n return 0;\n if (b > 1 && !ctx->buf_len) {\n *outl -= b;\n ctx->final_used = 1;\n memcpy(ctx->final, &out[*outl], b);\n } else\n ctx->final_used = 0;\n if (fix_len)\n *outl += b;\n return 1;\n}', 'static int is_partially_overlapping(const void *ptr1, const void *ptr2,\n int len)\n{\n PTRDIFF_T diff = (PTRDIFF_T)ptr1-(PTRDIFF_T)ptr2;\n int condition = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) |\n (diff > (0 - (PTRDIFF_T)len)));\n assert(!condition);\n return condition;\n}']
34,900
0
https://github.com/libav/libav/blob/2f99117f6ff24ce5be2abb9e014cb8b86c2aa0e0/libavcodec/bitstream.h/#L139
static inline uint64_t get_val(BitstreamContext *bc, unsigned n) { #ifdef BITSTREAM_READER_LE uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1); bc->bits >>= n; #else uint64_t ret = bc->bits >> (64 - n); bc->bits <<= n; #endif bc->bits_left -= n; return ret; }
['static int theora_header(AVFormatContext *s, int idx)\n{\n struct ogg *ogg = s->priv_data;\n struct ogg_stream *os = ogg->streams + idx;\n AVStream *st = s->streams[idx];\n TheoraParams *thp = os->private;\n int cds = st->codecpar->extradata_size + os->psize + 2;\n int err;\n uint8_t *cdp;\n if (!(os->buf[os->pstart] & 0x80))\n return 0;\n if (!thp) {\n thp = av_mallocz(sizeof(*thp));\n if (!thp)\n return AVERROR(ENOMEM);\n os->private = thp;\n }\n switch (os->buf[os->pstart]) {\n case 0x80: {\n BitstreamContext bc;\n AVRational timebase;\n bitstream_init(&bc, os->buf + os->pstart, os->psize * 8);\n bitstream_skip(&bc, 7 * 8);\n thp->version = bitstream_read(&bc, 24);\n if (thp->version < 0x030100) {\n av_log(s, AV_LOG_ERROR,\n "Too old or unsupported Theora (%x)\\n", thp->version);\n return AVERROR(ENOSYS);\n }\n st->codecpar->width = bitstream_read(&bc, 16) << 4;\n st->codecpar->height = bitstream_read(&bc, 16) << 4;\n if (thp->version >= 0x030400)\n bitstream_skip(&bc, 100);\n if (thp->version >= 0x030200) {\n int width = bitstream_read(&bc, 24);\n int height = bitstream_read(&bc, 24);\n if (width <= st->codecpar->width && width > st->codecpar->width - 16 &&\n height <= st->codecpar->height && height > st->codecpar->height - 16) {\n st->codecpar->width = width;\n st->codecpar->height = height;\n }\n bitstream_skip(&bc, 16);\n }\n timebase.den = bitstream_read(&bc, 32);\n timebase.num = bitstream_read(&bc, 32);\n if (!(timebase.num > 0 && timebase.den > 0)) {\n av_log(s, AV_LOG_WARNING, "Invalid time base in theora stream, assuming 25 FPS\\n");\n timebase.num = 1;\n timebase.den = 25;\n }\n avpriv_set_pts_info(st, 64, timebase.num, timebase.den);\n st->sample_aspect_ratio.num = bitstream_read(&bc, 24);\n st->sample_aspect_ratio.den = bitstream_read(&bc, 24);\n if (thp->version >= 0x030200)\n bitstream_skip(&bc, 38);\n if (thp->version >= 0x304000)\n bitstream_skip(&bc, 2);\n thp->gpshift = bitstream_read(&bc, 5);\n thp->gpmask = (1 << thp->gpshift) - 1;\n st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;\n st->codecpar->codec_id = AV_CODEC_ID_THEORA;\n st->need_parsing = AVSTREAM_PARSE_HEADERS;\n }\n break;\n case 0x81:\n ff_vorbis_stream_comment(s, st, os->buf + os->pstart + 7, os->psize - 7);\n case 0x82:\n if (!thp->version)\n return AVERROR_INVALIDDATA;\n break;\n default:\n return AVERROR_INVALIDDATA;\n }\n if ((err = av_reallocp(&st->codecpar->extradata,\n cds + AV_INPUT_BUFFER_PADDING_SIZE)) < 0) {\n st->codecpar->extradata_size = 0;\n return err;\n }\n cdp = st->codecpar->extradata + st->codecpar->extradata_size;\n *cdp++ = os->psize >> 8;\n *cdp++ = os->psize & 0xff;\n memcpy(cdp, os->buf + os->pstart, os->psize);\n st->codecpar->extradata_size = cds;\n return 1;\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n if (!n)\n return 0;\n if (n > bc->bits_left) {\n refill_32(bc);\n if (bc->bits_left < 32)\n bc->bits_left = n;\n }\n return get_val(bc, n);\n}', 'static inline uint64_t get_val(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);\n bc->bits >>= n;\n#else\n uint64_t ret = bc->bits >> (64 - n);\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n return ret;\n}']