Fix compiler warnings for VS2010 /W4 in config.c and encmain.c.

- Working towards issue #11.
- Widened datatypes for cfg struct members that take values from atoi to full
  ints so that bounds checking can be done after parsing without overflow.
This commit is contained in:
Ari Koivula 2014-02-21 15:15:59 +02:00
parent db3b96b90b
commit 73f5c3b80e
5 changed files with 26 additions and 25 deletions

View file

@ -130,12 +130,13 @@ static int atobool(const char *str)
static int parse_enum(const char *arg, const char * const *names, int8_t *dst) static int parse_enum(const char *arg, const char * const *names, int8_t *dst)
{ {
int i; int8_t i;
for (i = 0; names[i]; i++) for (i = 0; names[i]; i++) {
if (!strcmp(arg, names[i])) { if (!strcmp(arg, names[i])) {
*dst = i; *dst = i;
return 1; return 1;
} }
}
return 0; return 0;
} }

View file

@ -36,29 +36,29 @@ typedef struct
char *input; /*!< \brief Pointer to input filename */ char *input; /*!< \brief Pointer to input filename */
char *output; /*!< \brief Pointer to output filename */ char *output; /*!< \brief Pointer to output filename */
char *debug; /*!< \brief Pointer to debug output */ char *debug; /*!< \brief Pointer to debug output */
int8_t qp; /*!< \brief Quantization parameter */ int32_t qp; /*!< \brief Quantization parameter */
int16_t intra_period; /*!< \brief the period of intra frames in stream */ int32_t intra_period; /*!< \brief the period of intra frames in stream */
int32_t frames; /*!< \brief Number of frames to decode */ int32_t frames; /*!< \brief Number of frames to decode */
int32_t width; /*!< \brief frame width */ int32_t width; /*!< \brief frame width */
int32_t height; /*!< \brief frame height */ int32_t height; /*!< \brief frame height */
int8_t deblock_enable; /*!< \brief Flag to enable deblocking filter */ int32_t deblock_enable; /*!< \brief Flag to enable deblocking filter */
int8_t sao_enable; /*!< \brief Flag to enable sample adaptive offset filter */ int32_t sao_enable; /*!< \brief Flag to enable sample adaptive offset filter */
int8_t deblock_beta; /*!< \brief (deblocking) beta offset (div 2), range -6...6 */ int32_t deblock_beta; /*!< \brief (deblocking) beta offset (div 2), range -6...6 */
int8_t deblock_tc; /*!< \brief (deblocking) tc offset (div 2), range -6...6 */ int32_t deblock_tc; /*!< \brief (deblocking) tc offset (div 2), range -6...6 */
struct struct
{ {
int16_t sar_width; /*!< \brief the horizontal size of the sample aspect ratio (in arbitrary units) */ int32_t sar_width; /*!< \brief the horizontal size of the sample aspect ratio (in arbitrary units) */
int16_t sar_height; /*!< \brief the vertical size of the sample aspect ratio (in the same arbitrary units as sar_width). */ int32_t sar_height; /*!< \brief the vertical size of the sample aspect ratio (in the same arbitrary units as sar_width). */
int8_t overscan; /*!< \brief Crop overscan setting */ int8_t overscan; /*!< \brief Crop overscan setting */
int8_t videoformat; /*!< \brief Video format */ int8_t videoformat; /*!< \brief Video format */
int8_t fullrange; /*!< \brief Flag to indicate full-range */ int8_t fullrange; /*!< \brief Flag to indicate full-range */
int8_t colorprim; /*!< \brief Color primaries */ int8_t colorprim; /*!< \brief Color primaries */
int8_t transfer; /*!< \brief Transfer characteristics */ int8_t transfer; /*!< \brief Transfer characteristics */
int8_t colormatrix; /*!< \brief Color matrix coefficients */ int8_t colormatrix; /*!< \brief Color matrix coefficients */
int8_t chroma_loc; /*!< \brief Chroma sample location */ int32_t chroma_loc; /*!< \brief Chroma sample location */
} vui; } vui;
int8_t aud_enable; /*!< \brief Flag to use access unit delimiters */ int32_t aud_enable; /*!< \brief Flag to use access unit delimiters */
int8_t ref_frames; /*!< \brief number of reference frames to use */ int32_t ref_frames; /*!< \brief number of reference frames to use */
char * cqmfile; /*!< \brief Pointer to custom quantization matrices filename */ char * cqmfile; /*!< \brief Pointer to custom quantization matrices filename */
} config; } config;

View file

@ -180,26 +180,26 @@ int main(int argc, char *argv[])
// input init (TODO: read from commandline / config) // input init (TODO: read from commandline / config)
encoder->bitdepth = 8; encoder->bitdepth = 8;
encoder->frame = 0; encoder->frame = 0;
encoder->QP = encoder->cfg->qp; encoder->QP = (int8_t)encoder->cfg->qp;
encoder->in.video_format = FORMAT_420; encoder->in.video_format = FORMAT_420;
// deblocking filter // deblocking filter
encoder->deblock_enable = encoder->cfg->deblock_enable; encoder->deblock_enable = (int8_t)encoder->cfg->deblock_enable;
encoder->beta_offset_div2 = encoder->cfg->deblock_beta; encoder->beta_offset_div2 = (int8_t)encoder->cfg->deblock_beta;
encoder->tc_offset_div2 = encoder->cfg->deblock_tc; encoder->tc_offset_div2 = (int8_t)encoder->cfg->deblock_tc;
// SAO // SAO
encoder->sao_enable = encoder->cfg->sao_enable; encoder->sao_enable = (int8_t)encoder->cfg->sao_enable;
// VUI // VUI
encoder->vui.sar_width = encoder->cfg->vui.sar_width; encoder->vui.sar_width = (int16_t)encoder->cfg->vui.sar_width;
encoder->vui.sar_height = encoder->cfg->vui.sar_height; encoder->vui.sar_height = (int16_t)encoder->cfg->vui.sar_height;
encoder->vui.overscan = encoder->cfg->vui.overscan; encoder->vui.overscan = encoder->cfg->vui.overscan;
encoder->vui.videoformat = encoder->cfg->vui.videoformat; encoder->vui.videoformat = encoder->cfg->vui.videoformat;
encoder->vui.fullrange = encoder->cfg->vui.fullrange; encoder->vui.fullrange = encoder->cfg->vui.fullrange;
encoder->vui.colorprim = encoder->cfg->vui.colorprim; encoder->vui.colorprim = encoder->cfg->vui.colorprim;
encoder->vui.transfer = encoder->cfg->vui.transfer; encoder->vui.transfer = encoder->cfg->vui.transfer;
encoder->vui.colormatrix = encoder->cfg->vui.colormatrix; encoder->vui.colormatrix = encoder->cfg->vui.colormatrix;
encoder->vui.chroma_loc = encoder->cfg->vui.chroma_loc; encoder->vui.chroma_loc = (int8_t)encoder->cfg->vui.chroma_loc;
// AUD // AUD
encoder->aud_enable = encoder->cfg->aud_enable; encoder->aud_enable = (int8_t)encoder->cfg->aud_enable;
// CQM // CQM
cqmfile = cfg->cqmfile ? fopen(cfg->cqmfile, "rb") : NULL; cqmfile = cfg->cqmfile ? fopen(cfg->cqmfile, "rb") : NULL;
encoder->cqmfile = cqmfile; encoder->cqmfile = cqmfile;

View file

@ -268,7 +268,7 @@ encoder_control *init_encoder_control(config *cfg)
// input init (TODO: read from commandline / config) // input init (TODO: read from commandline / config)
enc_c->bitdepth = 8; enc_c->bitdepth = 8;
enc_c->frame = 0; enc_c->frame = 0;
enc_c->QP = enc_c->cfg->qp; enc_c->QP = (int8_t)enc_c->cfg->qp;
enc_c->in.video_format = FORMAT_420; enc_c->in.video_format = FORMAT_420;
// deblocking filter // deblocking filter
enc_c->deblock_enable = 1; enc_c->deblock_enable = 1;

View file

@ -141,8 +141,8 @@ typedef struct picture_struct
typedef struct typedef struct
{ {
picture** pics; //!< \brief Pointer to array of picture pointers. picture** pics; //!< \brief Pointer to array of picture pointers.
unsigned int size; //!< \brief Array size. int32_t size; //!< \brief Array size.
unsigned int used_size; int32_t used_size;
} picture_list; } picture_list;