Changeset 74ecbc7 for lib


Ignore:
Timestamp:
03/21/14 16:23:48 (8 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
dad224b
Parents:
1ca603b
Message:

Add more user-friendly checks for output file compression options

  • No longer assert fail if the level is outside the allowed range
  • Actually check that a valid compression method has been provided
  • Failing either check will result in NULL being returned by trace_open_file_out and the libtrace error being set appropriately
  • Added TRACE_OPTION_COMPRESSTYPE_LAST to compression method enum, so we can always easily tell if the value is outside the expected range.
Location:
lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/format_helper.c

    r8b49230 r74ecbc7  
    263263{
    264264        iow_t *io = NULL;
    265         assert(level<10);
    266         assert(level>=0);
     265
     266        if (level < 0 || level > 9) {
     267                trace_set_err_out(trace, TRACE_ERR_UNSUPPORTED_COMPRESS,
     268                                "Compression level %d is invalid, must be between 0 and 9 inclusive",
     269                                level);
     270                return NULL;
     271        }
     272
     273        if (compress_type < 0 ||
     274                        compress_type >= TRACE_OPTION_COMPRESSTYPE_LAST) {
     275                trace_set_err_out(trace, TRACE_ERR_UNSUPPORTED_COMPRESS,
     276                                "Invalid compression type %d", compress_type);
     277                return NULL;
     278        }
    267279
    268280        io = wandio_wcreate(trace->uridata, compress_type, level, fileflag);
  • lib/libtrace.h.in

    rf7bcbfb r74ecbc7  
    12101210        TRACE_OPTION_COMPRESSTYPE_ZLIB = 1, /**< GZip Compression */
    12111211        TRACE_OPTION_COMPRESSTYPE_BZ2  = 2, /**< BZip2 Compression */
    1212         TRACE_OPTION_COMPRESSTYPE_LZO  = 3  /**< LZO Compression */
     1212        TRACE_OPTION_COMPRESSTYPE_LZO  = 3,  /**< LZO Compression */
     1213        TRACE_OPTION_COMPRESSTYPE_LAST
    12131214} trace_option_compresstype_t;
    12141215
Note: See TracChangeset for help on using the changeset viewer.