MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / opt_get_array

Function opt_get_array

libavutil/opt.c:1155–1213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1153}
1154
1155static int opt_get_array(const AVOption *o, void *dst, uint8_t **out_val)
1156{
1157 const unsigned count = *opt_array_pcount(dst);
1158 const uint8_t sep = opt_array_sep(o);
1159
1160 uint8_t *str = NULL;
1161 size_t str_len = 0;
1162 int ret;
1163
1164 *out_val = NULL;
1165
1166 for (unsigned i = 0; i < count; i++) {
1167 uint8_t buf[128], *out = buf;
1168 size_t out_len;
1169
1170 ret = opt_get_elem(o, &out, sizeof(buf),
1171 opt_array_pelem(o, *(void **)dst, i), 0);
1172 if (ret < 0)
1173 goto fail;
1174
1175 out_len = strlen(out);
1176 if (out_len > SIZE_MAX / 2 - !!i ||
1177 !!i + out_len * 2 > SIZE_MAX - str_len - 1) {
1178 ret = AVERROR(ERANGE);
1179 goto fail;
1180 }
1181
1182 // terminator escaping separator
1183 // ↓ ↓ ↓
1184 ret = av_reallocp(&str, str_len + 1 + out_len * 2 + !!i);
1185 if (ret < 0)
1186 goto fail;
1187
1188 // add separator if needed
1189 if (i)
1190 str[str_len++] = sep;
1191
1192 // escape the element
1193 for (unsigned j = 0; j < out_len; j++) {
1194 uint8_t val = out[j];
1195 if (val == sep || val == '\\')
1196 str[str_len++] = '\\';
1197 str[str_len++] = val;
1198 }
1199 str[str_len] = 0;
1200
1201fail:
1202 if (out != buf)
1203 av_freep(&out);
1204 if (ret < 0) {
1205 av_freep(&str);
1206 return ret;
1207 }
1208 }
1209
1210 *out_val = str;
1211
1212 return 0;

Callers 2

av_opt_getFunction · 0.85
av_opt_is_set_to_defaultFunction · 0.85

Calls 6

opt_array_pcountFunction · 0.85
opt_array_sepFunction · 0.85
opt_get_elemFunction · 0.85
opt_array_pelemFunction · 0.85
av_reallocpFunction · 0.85
av_freepFunction · 0.85

Tested by

no test coverage detected