static int read_shape_from_file(int *cols, int *rows, int **values, const char *filename,

                                void *log_ctx)

{

    uint8_t *buf, *p, *pend;

    size_t size;

    int ret, i, j, w;



    if ((ret = av_file_map(filename, &buf, &size, 0, log_ctx)) < 0)

        return ret;



    /* prescan file to get the number of lines and the maximum width */

    w = 0;

    for (i = 0; i < size; i++) {

        if (buf[i] == '\n') {

            if (*rows == INT_MAX) {

                av_log(log_ctx, AV_LOG_ERROR, "Overflow on the number of rows in the file\n");

                return AVERROR_INVALIDDATA;

            }

            ++(*rows);

            *cols = FFMAX(*cols, w);

            w = 0;

        } else if (w == INT_MAX) {

            av_log(log_ctx, AV_LOG_ERROR, "Overflow on the number of columns in the file\n");

            return AVERROR_INVALIDDATA;

        }

        w++;

    }

    if (*rows > (SIZE_MAX / sizeof(int) / *cols)) {

        av_log(log_ctx, AV_LOG_ERROR, "File with size %dx%d is too big\n",

               *rows, *cols);

        return AVERROR_INVALIDDATA;

    }

    if (!(*values = av_mallocz_array(sizeof(int) * *rows, *cols)))

        return AVERROR(ENOMEM);



    /* fill *values */

    p    = buf;

    pend = buf + size-1;

    for (i = 0; i < *rows; i++) {

        for (j = 0;; j++) {

            if (p > pend || *p == '\n') {

                p++;

                break;

            } else

                (*values)[*cols*i + j] = !!av_isgraph(*(p++));

        }

    }

    av_file_unmap(buf, size);



#ifdef DEBUG

    {

        char *line;

        if (!(line = av_malloc(*cols + 1)))

            return AVERROR(ENOMEM);

        for (i = 0; i < *rows; i++) {

            for (j = 0; j < *cols; j++)

                line[j] = (*values)[i * *cols + j] ? '@' : ' ';

            line[j] = 0;

            av_log(log_ctx, AV_LOG_DEBUG, "%3d: %s\n", i, line);

        }

        av_free(line);

    }

#endif



    return 0;

}

static int read_shape_from_file(int *cols, int *rows, int **values, const char *filename,

                                void *log_ctx)

{

    uint8_t *buf, *p, *pend;

    size_t size;

    int ret, i, j, w;



    if ((ret = av_file_map(filename, &buf, &size, 0, log_ctx)) < 0)

        return ret;



    

    w = 0;

    for (i = 0; i < size; i++) {

        if (buf[i] == '\n') {

            if (*rows == INT_MAX) {

                av_log(log_ctx, AV_LOG_ERROR, "Overflow on the number of rows in the file\n");

                return AVERROR_INVALIDDATA;

            }

            ++(*rows);

            *cols = FFMAX(*cols, w);

            w = 0;

        } else if (w == INT_MAX) {

            av_log(log_ctx, AV_LOG_ERROR, "Overflow on the number of columns in the file\n");

            return AVERROR_INVALIDDATA;

        }

        w++;

    }

    if (*rows > (SIZE_MAX / sizeof(int) / *cols)) {

        av_log(log_ctx, AV_LOG_ERROR, "File with size %dx%d is too big\n",

               *rows, *cols);

        return AVERROR_INVALIDDATA;

    }

    if (!(*values = av_mallocz_array(sizeof(int) * *rows, *cols)))

        return AVERROR(ENOMEM);



    

    p    = buf;

    pend = buf + size-1;

    for (i = 0; i < *rows; i++) {

        for (j = 0;; j++) {

            if (p > pend || *p == '\n') {

                p++;

                break;

            } else

                (*values)[*cols*i + j] = !!av_isgraph(*(p++));

        }

    }

    av_file_unmap(buf, size);



#ifdef DEBUG

    {

        char *line;

        if (!(line = av_malloc(*cols + 1)))

            return AVERROR(ENOMEM);

        for (i = 0; i < *rows; i++) {

            for (j = 0; j < *cols; j++)

                line[j] = (*values)[i * *cols + j] ? '@' : ' ';

            line[j] = 0;

            av_log(log_ctx, AV_LOG_DEBUG, "%3d: %s\n", i, line);

        }

        av_free(line);

    }

#endif



    return 0;

}

                return AVERROR_INVALIDDATA;         return AVERROR_INVALIDDATA;     if (!(*values = av_mallocz_array(sizeof(int) * *rows, *cols)))         return AVERROR(ENOMEM);
static int FUNC_0(int *VAR_0, int *VAR_1, int **VAR_2, const char *VAR_3,

                                void *VAR_4)

{

    uint8_t *buf, *p, *pend;

    size_t size;

    int VAR_5, VAR_6, VAR_7, VAR_8;



    if ((VAR_5 = av_file_map(VAR_3, &buf, &size, 0, VAR_4)) < 0)

        return VAR_5;



    

    VAR_8 = 0;

    for (VAR_6 = 0; VAR_6 < size; VAR_6++) {

        if (buf[VAR_6] == '\n') {

            if (*VAR_1 == INT_MAX) {

                av_log(VAR_4, AV_LOG_ERROR, "Overflow on the number of VAR_1 in the file\n");

                return AVERROR_INVALIDDATA;

            }

            ++(*VAR_1);

            *VAR_0 = FFMAX(*VAR_0, VAR_8);

            VAR_8 = 0;

        } else if (VAR_8 == INT_MAX) {

            av_log(VAR_4, AV_LOG_ERROR, "Overflow on the number of columns in the file\n");

            return AVERROR_INVALIDDATA;

        }

        VAR_8++;

    }

    if (*VAR_1 > (SIZE_MAX / sizeof(int) / *VAR_0)) {

        av_log(VAR_4, AV_LOG_ERROR, "File with size %dx%d is too big\n",

               *VAR_1, *VAR_0);

        return AVERROR_INVALIDDATA;

    }

    if (!(*VAR_2 = av_mallocz_array(sizeof(int) * *VAR_1, *VAR_0)))

        return AVERROR(ENOMEM);



    

    p    = buf;

    pend = buf + size-1;

    for (VAR_6 = 0; VAR_6 < *VAR_1; VAR_6++) {

        for (VAR_7 = 0;; VAR_7++) {

            if (p > pend || *p == '\n') {

                p++;

                break;

            } else

                (*VAR_2)[*VAR_0*VAR_6 + VAR_7] = !!av_isgraph(*(p++));

        }

    }

    av_file_unmap(buf, size);



#ifdef DEBUG

    {

        char *line;

        if (!(line = av_malloc(*VAR_0 + 1)))

            return AVERROR(ENOMEM);

        for (VAR_6 = 0; VAR_6 < *VAR_1; VAR_6++) {

            for (VAR_7 = 0; VAR_7 < *VAR_0; VAR_7++)

                line[VAR_7] = (*VAR_2)[VAR_6 * *VAR_0 + VAR_7] ? '@' : ' ';

            line[VAR_7] = 0;

            av_log(VAR_4, AV_LOG_DEBUG, "%3d: %s\n", VAR_6, line);

        }

        av_free(line);

    }

#endif



    return 0;

}

static int FUNC_0(int *VAR_0, int *VAR_1, int **VAR_2, const char *VAR_3,
void *VAR_4)
{ uint8_t *buf, *p, *pend; size_t size; int VAR_5, VAR_6, VAR_7, VAR_8; if ((VAR_5 = av_file_map(VAR_3, &buf, &size, 0, VAR_4)) < 0)
return VAR_5; VAR_8 = 0; for (VAR_6 = 0; VAR_6 < size; VAR_6++) { if (buf[VAR_6] == '\n') { if (*VAR_1 == INT_MAX) { av_log(VAR_4, AV_LOG_ERROR, "Overflow on the number of VAR_1 in the file\n"); return AVERROR_INVALIDDATA; } ++(*VAR_1); *VAR_0 = FFMAX(*VAR_0, VAR_8); VAR_8 = 0; } else if (VAR_8 == INT_MAX) { av_log(VAR_4, AV_LOG_ERROR, "Overflow on the number of columns in the file\n"); return AVERROR_INVALIDDATA; } VAR_8++; } if (*VAR_1 > (SIZE_MAX / sizeof(int) / *VAR_0)) { av_log(VAR_4, AV_LOG_ERROR, "File with size %dx%d is too big\n",
*VAR_1, *VAR_0); return AVERROR_INVALIDDATA; } if (!(*VAR_2 = av_mallocz_array(sizeof(int) * *VAR_1, *VAR_0)))
return AVERROR(ENOMEM); p    = buf; pend = buf + size-1; for (VAR_6 = 0; VAR_6 < *VAR_1; VAR_6++) { for (VAR_7 = 0;; VAR_7++) { if (p > pend || *p == '\n') { p++; break; } else (*VAR_2)[*VAR_0*VAR_6 + VAR_7] = !!av_isgraph(*(p++)); } } av_file_unmap(buf, size); #ifdef DEBUG
{ char *line; if (!(line = av_malloc(*VAR_0 + 1)))
return AVERROR(ENOMEM); for (VAR_6 = 0; VAR_6 < *VAR_1; VAR_6++) { for (VAR_7 = 0; VAR_7 < *VAR_0; VAR_7++) line[VAR_7] = (*VAR_2)[VAR_6 * *VAR_0 + VAR_7] ? '@' : ' '; line[VAR_7] = 0; av_log(VAR_4, AV_LOG_DEBUG, "%3d: %s\n", VAR_6, line); } av_free(line); } #endif
return 0; }