int main(void) { int i; AVTreeNode *root = NULL, *node = NULL; AVLFG prng; av_lfg_init(&prng, 1); for (i = 0; i < 10000; i++) { AVTreeNode *node2 = NULL; intptr_t j = av_lfg_get(&prng) % 86294; void *ret, *jj = (void *)(j + 1); while (ret = av_tree_find(root, jj, cmp, NULL)) { j = av_lfg_get(&prng) % 86294; jj = (void *)(j + 1); } if (check(root) > 999) { av_log(NULL, AV_LOG_ERROR, "FATAL error %d\n", i); print(root, 0); return 1; } if (!node) node = av_tree_node_alloc(); if (!node) { av_log(NULL, AV_LOG_ERROR, "Memory allocation failure.\n"); return 1; } av_tree_insert(&root, jj, cmp, &node); while (ret = av_tree_find(root, jj, cmp, NULL)) { j = av_lfg_get(&prng) % 86294; jj = (void *)(j + 1); } ret = av_tree_insert(&root, jj, cmp, &node2); if (ret != jj) av_tree_destroy(node2); ret = av_tree_find(root, jj, cmp, NULL); if (ret) av_log(NULL, AV_LOG_ERROR, "removal failure %d\n", i); } av_tree_destroy(root); return 0; }
int main(int argc, char **argv) { int i; void *k; AVTreeNode *root = NULL, *node = NULL; AVLFG prng; int log_level = argc <= 1 ? AV_LOG_INFO : atoi(argv[1]); av_log_set_level(log_level); av_lfg_init(&prng, 1); for (i = 0; i < 10000; i++) { intptr_t j = av_lfg_get(&prng) % 86294; if (check(root) > 999) { av_log(NULL, AV_LOG_ERROR, "FATAL error %d\n", i); print(root, 0); return 1; } av_log(NULL, AV_LOG_DEBUG, "inserting %4d\n", (int)j); if (!node) node = av_tree_node_alloc(); if (!node) { av_log(NULL, AV_LOG_ERROR, "Memory allocation failure.\n"); return 1; } av_tree_insert(&root, (void *)(j + 1), cmp, &node); j = av_lfg_get(&prng) % 86294; { AVTreeNode *node2 = NULL; av_log(NULL, AV_LOG_DEBUG, "removing %4d\n", (int)j); av_tree_insert(&root, (void *)(j + 1), cmp, &node2); k = av_tree_find(root, (void *)(j + 1), cmp, NULL); if (k) av_log(NULL, AV_LOG_ERROR, "removal failure %d\n", i); av_free(node2); } } av_free(node); av_tree_destroy(root); return 0; }
/** * Load glyphs corresponding to the UTF-32 codepoint code. */ static int load_glyph(AVFilterContext *ctx, Glyph **glyph_ptr, uint32_t code) { DrawTextContext *s = ctx->priv; Glyph *glyph; struct AVTreeNode *node = NULL; int ret; /* load glyph into s->face->glyph */ if (FT_Load_Char(s->face, code, s->ft_load_flags)) return AVERROR(EINVAL); /* save glyph */ if (!(glyph = av_mallocz(sizeof(*glyph))) || !(glyph->glyph = av_mallocz(sizeof(*glyph->glyph)))) { ret = AVERROR(ENOMEM); goto error; } glyph->code = code; if (FT_Get_Glyph(s->face->glyph, glyph->glyph)) { ret = AVERROR(EINVAL); goto error; } glyph->bitmap = s->face->glyph->bitmap; glyph->bitmap_left = s->face->glyph->bitmap_left; glyph->bitmap_top = s->face->glyph->bitmap_top; glyph->advance = s->face->glyph->advance.x >> 6; /* measure text height to calculate text_height (or the maximum text height) */ FT_Glyph_Get_CBox(*glyph->glyph, ft_glyph_bbox_pixels, &glyph->bbox); /* cache the newly created glyph */ if (!(node = av_tree_node_alloc())) { ret = AVERROR(ENOMEM); goto error; } av_tree_insert(&s->glyphs, glyph, glyph_cmp, &node); if (glyph_ptr) *glyph_ptr = glyph; return 0; error: if (glyph) av_freep(&glyph->glyph); av_freep(&glyph); av_freep(&node); return ret; }
/** * Load glyphs corresponding to the UTF-32 codepoint code. */ static int load_glyph(AVFilterContext *ctx, Glyph **glyph_ptr, uint32_t code) { DrawTextContext *s = ctx->priv; FT_BitmapGlyph bitmapglyph; Glyph *glyph; struct AVTreeNode *node = NULL; int ret; /* load glyph into s->face->glyph */ if (FT_Load_Char(s->face, code, s->ft_load_flags)) return AVERROR(EINVAL); glyph = av_mallocz(sizeof(*glyph)); if (!glyph) { ret = AVERROR(ENOMEM); goto error; } glyph->code = code; if (FT_Get_Glyph(s->face->glyph, &glyph->glyph)) { ret = AVERROR(EINVAL); goto error; } if (s->borderw) { glyph->border_glyph = glyph->glyph; if (FT_Glyph_StrokeBorder(&glyph->border_glyph, s->stroker, 0, 0) || FT_Glyph_To_Bitmap(&glyph->border_glyph, FT_RENDER_MODE_NORMAL, 0, 1)) { ret = AVERROR_EXTERNAL; goto error; } bitmapglyph = (FT_BitmapGlyph) glyph->border_glyph; glyph->border_bitmap = bitmapglyph->bitmap; } if (FT_Glyph_To_Bitmap(&glyph->glyph, FT_RENDER_MODE_NORMAL, 0, 1)) { ret = AVERROR_EXTERNAL; goto error; } bitmapglyph = (FT_BitmapGlyph) glyph->glyph; glyph->bitmap = bitmapglyph->bitmap; glyph->bitmap_left = bitmapglyph->left; glyph->bitmap_top = bitmapglyph->top; glyph->advance = s->face->glyph->advance.x >> 6; /* measure text height to calculate text_height (or the maximum text height) */ FT_Glyph_Get_CBox(glyph->glyph, ft_glyph_bbox_pixels, &glyph->bbox); /* cache the newly created glyph */ if (!(node = av_tree_node_alloc())) { ret = AVERROR(ENOMEM); goto error; } av_tree_insert(&s->glyphs, glyph, glyph_cmp, &node); if (glyph_ptr) *glyph_ptr = glyph; return 0; error: if (glyph) av_freep(&glyph->glyph); av_freep(&glyph); av_freep(&node); return ret; }