Message ID | 20200518033033.27347-1-andreas.rheinhardt@gmail.com |
---|---|
State | Accepted |
Commit | 325c901430781ad2d915828389a8ed5f1ad849bc |
Headers | show |
Series | [FFmpeg-devel,1/5] avformat/webmdashenc: Avoid allocation for parsing a number | expand |
Context | Check | Description |
---|---|---|
andriy/default | pending | |
andriy/make | success | Make finished |
andriy/make_fate | success | Make fate finished |
Andreas Rheinhardt: > In order to parse a number from a string, the WebM DASH manifest muxer > would duplicate (via heap-allocation) the part of the string that > contains the number, then read the number via atoi() and then free the > duplicate again. This has been replaced by simply using strtoll() (which > in contrast to atoi() has defined behaviour when the number is not > representable). > > Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> > --- > libavformat/webmdashenc.c | 14 +------------- > 1 file changed, 1 insertion(+), 13 deletions(-) > > diff --git a/libavformat/webmdashenc.c b/libavformat/webmdashenc.c > index 465485c90c..05015a08c1 100644 > --- a/libavformat/webmdashenc.c > +++ b/libavformat/webmdashenc.c > @@ -425,18 +425,6 @@ static int write_adaptation_set(AVFormatContext *s, int as_index) > return 0; > } > > -static int to_integer(char *p, int len) > -{ > - int ret; > - char *q = av_malloc(len); > - if (!q) > - return AVERROR(ENOMEM); > - av_strlcpy(q, p, len); > - ret = atoi(q); > - av_free(q); > - return ret; > -} > - > static int parse_adaptation_sets(AVFormatContext *s) > { > WebMDashMuxContext *w = s->priv_data; > @@ -483,7 +471,7 @@ static int parse_adaptation_sets(AVFormatContext *s) > return ret; > q = p; > while (*q != '\0' && *q != ',' && *q != ' ') q++; > - as->streams[as->nb_streams - 1] = to_integer(p, q - p + 1); > + as->streams[as->nb_streams - 1] = strtoll(p, NULL, 10); > if (as->streams[as->nb_streams - 1] < 0 || > as->streams[as->nb_streams - 1] >= s->nb_streams) { > av_log(s, AV_LOG_ERROR, "Invalid value for 'streams' in adapation_sets.\n"); > Will apply this patchset tomorrow unless there are objections. - Andreas
Andreas Rheinhardt: > Andreas Rheinhardt: >> In order to parse a number from a string, the WebM DASH manifest muxer >> would duplicate (via heap-allocation) the part of the string that >> contains the number, then read the number via atoi() and then free the >> duplicate again. This has been replaced by simply using strtoll() (which >> in contrast to atoi() has defined behaviour when the number is not >> representable). >> >> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> >> --- >> libavformat/webmdashenc.c | 14 +------------- >> 1 file changed, 1 insertion(+), 13 deletions(-) >> >> diff --git a/libavformat/webmdashenc.c b/libavformat/webmdashenc.c >> index 465485c90c..05015a08c1 100644 >> --- a/libavformat/webmdashenc.c >> +++ b/libavformat/webmdashenc.c >> @@ -425,18 +425,6 @@ static int write_adaptation_set(AVFormatContext *s, int as_index) >> return 0; >> } >> >> -static int to_integer(char *p, int len) >> -{ >> - int ret; >> - char *q = av_malloc(len); >> - if (!q) >> - return AVERROR(ENOMEM); >> - av_strlcpy(q, p, len); >> - ret = atoi(q); >> - av_free(q); >> - return ret; >> -} >> - >> static int parse_adaptation_sets(AVFormatContext *s) >> { >> WebMDashMuxContext *w = s->priv_data; >> @@ -483,7 +471,7 @@ static int parse_adaptation_sets(AVFormatContext *s) >> return ret; >> q = p; >> while (*q != '\0' && *q != ',' && *q != ' ') q++; >> - as->streams[as->nb_streams - 1] = to_integer(p, q - p + 1); >> + as->streams[as->nb_streams - 1] = strtoll(p, NULL, 10); >> if (as->streams[as->nb_streams - 1] < 0 || >> as->streams[as->nb_streams - 1] >= s->nb_streams) { >> av_log(s, AV_LOG_ERROR, "Invalid value for 'streams' in adapation_sets.\n"); >> > Will apply this patchset tomorrow unless there are objections. > > - Andreas > Applied. - Andreas
diff --git a/libavformat/webmdashenc.c b/libavformat/webmdashenc.c index 465485c90c..05015a08c1 100644 --- a/libavformat/webmdashenc.c +++ b/libavformat/webmdashenc.c @@ -425,18 +425,6 @@ static int write_adaptation_set(AVFormatContext *s, int as_index) return 0; } -static int to_integer(char *p, int len) -{ - int ret; - char *q = av_malloc(len); - if (!q) - return AVERROR(ENOMEM); - av_strlcpy(q, p, len); - ret = atoi(q); - av_free(q); - return ret; -} - static int parse_adaptation_sets(AVFormatContext *s) { WebMDashMuxContext *w = s->priv_data; @@ -483,7 +471,7 @@ static int parse_adaptation_sets(AVFormatContext *s) return ret; q = p; while (*q != '\0' && *q != ',' && *q != ' ') q++; - as->streams[as->nb_streams - 1] = to_integer(p, q - p + 1); + as->streams[as->nb_streams - 1] = strtoll(p, NULL, 10); if (as->streams[as->nb_streams - 1] < 0 || as->streams[as->nb_streams - 1] >= s->nb_streams) { av_log(s, AV_LOG_ERROR, "Invalid value for 'streams' in adapation_sets.\n");
In order to parse a number from a string, the WebM DASH manifest muxer would duplicate (via heap-allocation) the part of the string that contains the number, then read the number via atoi() and then free the duplicate again. This has been replaced by simply using strtoll() (which in contrast to atoi() has defined behaviour when the number is not representable). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> --- libavformat/webmdashenc.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-)