comparison opt.c @ 7224:d5a52b28c9de libavcodec

Fix the av_set_string() free / alloc issue.
author michael
date Tue, 08 Jul 2008 23:50:03 +0000
parents 322023e630a6
children 8c58eeb20826
comparison
equal deleted inserted replaced
7223:0133a6c7480f 7224:d5a52b28c9de
113 if (c >= 'a' && c <= 'f') return c - 'a' + 10; 113 if (c >= 'a' && c <= 'f') return c - 'a' + 10;
114 if (c >= 'A' && c <= 'F') return c - 'A' + 10; 114 if (c >= 'A' && c <= 'F') return c - 'A' + 10;
115 return -1; 115 return -1;
116 } 116 }
117 117
118 const AVOption *av_set_string(void *obj, const char *name, const char *val){ 118 const AVOption *av_set_string2(void *obj, const char *name, const char *val, int alloc){
119 const AVOption *o= av_find_opt(obj, name, NULL, 0, 0); 119 const AVOption *o= av_find_opt(obj, name, NULL, 0, 0);
120 if(o && o->offset==0 && o->type == FF_OPT_TYPE_CONST && o->unit){ 120 if(o && o->offset==0 && o->type == FF_OPT_TYPE_CONST && o->unit){
121 return set_all_opt(obj, o->unit, o->default_val); 121 return set_all_opt(obj, o->unit, o->default_val);
122 } 122 }
123 if(!o || !val || o->offset<=0) 123 if(!o || !val || o->offset<=0)
193 notfirst=1; 193 notfirst=1;
194 } 194 }
195 return NULL; 195 return NULL;
196 } 196 }
197 197
198 if(alloc){
199 av_free((void*)(((uint8_t*)obj) + o->offset));
200 val= av_strdup(val);
201 }
202
198 memcpy(((uint8_t*)obj) + o->offset, &val, sizeof(val)); 203 memcpy(((uint8_t*)obj) + o->offset, &val, sizeof(val));
199 return o; 204 return o;
205 }
206
207 const AVOption *av_set_string(void *obj, const char *name, const char *val){
208 return av_set_string2(obj, name, val, 0);
200 } 209 }
201 210
202 const AVOption *av_set_double(void *obj, const char *name, double n){ 211 const AVOption *av_set_double(void *obj, const char *name, double n){
203 return av_set_number(obj, name, n, 1, 1); 212 return av_set_number(obj, name, n, 1, 1);
204 } 213 }