fuzzer_parser_init:
   33|  1.53k|readstat_parser_t *fuzzer_parser_init(const uint8_t *Data, size_t Size) {
   34|  1.53k|    readstat_parser_t *parser = readstat_parser_init();
   35|  1.53k|    readstat_set_open_handler(parser, rt_open_handler);
   36|  1.53k|    readstat_set_close_handler(parser, rt_close_handler);
   37|  1.53k|    readstat_set_seek_handler(parser, rt_seek_handler);
   38|  1.53k|    readstat_set_read_handler(parser, rt_read_handler);
   39|  1.53k|    readstat_set_update_handler(parser, rt_update_handler);
   40|       |
   41|  1.53k|    readstat_set_metadata_handler(parser, &handle_metadata);
   42|  1.53k|    readstat_set_note_handler(parser, &handle_note);
   43|  1.53k|    readstat_set_variable_handler(parser, &handle_variable);
   44|  1.53k|    readstat_set_fweight_handler(parser, &handle_fweight);
   45|  1.53k|    readstat_set_value_handler(parser, &handle_value);
   46|  1.53k|    readstat_set_value_label_handler(parser, &handle_value_label);
   47|       |
   48|  1.53k|    return parser;
   49|  1.53k|}
fuzz_format.c:handle_metadata:
    8|  1.04k|static int handle_metadata(readstat_metadata_t *metadata, void *ctx) {
    9|  1.04k|    return READSTAT_HANDLER_OK;
   10|  1.04k|}
fuzz_format.c:handle_variable:
   21|  18.8k|                           const char *val_labels, void *ctx) {
   22|  18.8k|    return READSTAT_HANDLER_OK;
   23|  18.8k|}
fuzz_format.c:handle_value:
   25|  43.1k|static int handle_value(int obs_index, readstat_variable_t *variable, readstat_value_t value, void *ctx) {
   26|  43.1k|    return READSTAT_HANDLER_OK;
   27|  43.1k|}

LLVMFuzzerTestOneInput:
   10|  1.53k|int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
   11|  1.53k|    rt_buffer_t buffer = { .bytes = (char *)Data, .size = Size, .used = Size };
   12|  1.53k|    rt_buffer_ctx_t buffer_ctx = { .buffer = &buffer };
   13|       |
   14|  1.53k|    readstat_parser_t *parser = fuzzer_parser_init(Data, Size);
   15|  1.53k|    readstat_set_io_ctx(parser, &buffer_ctx);
   16|       |
   17|  1.53k|    readstat_parse_xport(parser, NULL, NULL);
   18|  1.53k|    readstat_parser_free(parser);
   19|  1.53k|    return 0;
   20|  1.53k|}

machine_is_little_endian:
   11|   187k|int machine_is_little_endian(void) {
   12|   187k|    int test_byte_order = 1;
   13|   187k|    return ((char *)&test_byte_order)[0];
   14|   187k|}
byteswap2:
   40|   971k|uint16_t byteswap2(uint16_t num) {
   41|   971k|    return ((num & 0xFF00) >> 8) | ((num & 0x00FF) << 8);
   42|   971k|}
byteswap4:
   44|  96.7k|uint32_t byteswap4(uint32_t num) {
   45|  96.7k|    num = ((num & 0xFFFF0000) >> 16) | ((num & 0x0000FFFF) << 16);
   46|  96.7k|    return ((num & 0xFF00FF00) >> 8) | ((num & 0x00FF00FF) << 8);
   47|  96.7k|}

readstat_convert:
    7|   392k|readstat_error_t readstat_convert(char *dst, size_t dst_len, const char *src, size_t src_len, iconv_t converter) {
    8|       |    /* strip off spaces from the input because the programs use ASCII space
    9|       |     * padding even with non-ASCII encoding. */
   10|  6.30M|    while (src_len && (src[src_len-1] == ' ' || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (10:12): [True: 6.06M, False: 238k]
  |  Branch (10:24): [True: 2.70M, False: 3.36M]
  |  Branch (10:49): [True: 3.21M, False: 154k]
  ------------------
   11|  5.91M|        src_len--;
   12|  5.91M|    }
   13|   392k|    if (dst_len == 0) {
  ------------------
  |  Branch (13:9): [True: 0, False: 392k]
  ------------------
   14|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   15|   392k|    } else if (converter) {
  ------------------
  |  Branch (15:16): [True: 0, False: 392k]
  ------------------
   16|      0|        size_t dst_left = dst_len - 1;
   17|      0|        char *dst_end = dst;
   18|      0|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   19|      0|        if (status == (size_t)-1) {
  ------------------
  |  Branch (19:13): [True: 0, False: 0]
  ------------------
   20|      0|            if (errno == E2BIG) {
  ------------------
  |  Branch (20:17): [True: 0, False: 0]
  ------------------
   21|      0|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   22|      0|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (22:24): [True: 0, False: 0]
  ------------------
   23|      0|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   24|      0|            } else if (errno != EINVAL) { /* EINVAL indicates improper truncation; accept it */
  ------------------
  |  Branch (24:24): [True: 0, False: 0]
  ------------------
   25|      0|                return READSTAT_ERROR_CONVERT;
   26|      0|            }
   27|      0|        }
   28|      0|        dst[dst_len - dst_left - 1] = '\0';
   29|   392k|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (29:16): [True: 22, False: 392k]
  ------------------
   30|     22|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   31|   392k|    } else {
   32|   392k|        memcpy(dst, src, src_len);
   33|   392k|        dst[src_len] = '\0';
   34|   392k|    }
   35|   392k|    return READSTAT_OK;
   36|   392k|}

unistd_io_init:
  121|  1.53k|readstat_error_t unistd_io_init(readstat_parser_t *parser) {
  122|  1.53k|    readstat_error_t retval = READSTAT_OK;
  123|  1.53k|    unistd_io_ctx_t *io_ctx = NULL;
  124|       |
  125|  1.53k|    if ((retval = readstat_set_open_handler(parser, unistd_open_handler)) != READSTAT_OK)
  ------------------
  |  Branch (125:9): [True: 0, False: 1.53k]
  ------------------
  126|      0|        return retval;
  127|       |
  128|  1.53k|    if ((retval = readstat_set_close_handler(parser, unistd_close_handler)) != READSTAT_OK)
  ------------------
  |  Branch (128:9): [True: 0, False: 1.53k]
  ------------------
  129|      0|        return retval;
  130|       |
  131|  1.53k|    if ((retval = readstat_set_seek_handler(parser, unistd_seek_handler)) != READSTAT_OK)
  ------------------
  |  Branch (131:9): [True: 0, False: 1.53k]
  ------------------
  132|      0|        return retval;
  133|       |
  134|  1.53k|    if ((retval = readstat_set_read_handler(parser, unistd_read_handler)) != READSTAT_OK)
  ------------------
  |  Branch (134:9): [True: 0, False: 1.53k]
  ------------------
  135|      0|        return retval;
  136|       |
  137|  1.53k|    if ((readstat_set_update_handler(parser, unistd_update_handler)) != READSTAT_OK)
  ------------------
  |  Branch (137:9): [True: 0, False: 1.53k]
  ------------------
  138|      0|        return retval;
  139|       |
  140|  1.53k|    io_ctx = calloc(1, sizeof(unistd_io_ctx_t));
  141|  1.53k|    io_ctx->fd = -1;
  142|       |
  143|  1.53k|    retval = readstat_set_io_ctx(parser, (void*) io_ctx);
  144|  1.53k|    parser->io->io_ctx_needs_free = 1;
  145|       |
  146|  1.53k|    return retval;
  147|  1.53k|}

readstat_malloc:
   10|  1.12k|void *readstat_malloc(size_t len) {
   11|  1.12k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  2.24k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (11:9): [True: 14, False: 1.11k]
  |  Branch (11:34): [True: 0, False: 1.11k]
  ------------------
   12|     14|        return NULL;
   13|     14|    }
   14|  1.11k|    return malloc(len);
   15|  1.12k|}
readstat_calloc:
   17|  1.06k|void *readstat_calloc(size_t count, size_t size) {
   18|  1.06k|    if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  2.12k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  2.11k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  1.04k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (18:9): [True: 14, False: 1.04k]
  |  Branch (18:36): [True: 0, False: 1.04k]
  |  Branch (18:62): [True: 0, False: 1.04k]
  ------------------
   19|     14|        return NULL;
   20|     14|    }
   21|  1.04k|    if (count == 0 || size == 0) {
  ------------------
  |  Branch (21:9): [True: 1, False: 1.04k]
  |  Branch (21:23): [True: 0, False: 1.04k]
  ------------------
   22|      1|        return NULL;
   23|      1|    }
   24|  1.04k|    return calloc(count, size);
   25|  1.04k|}
readstat_realloc:
   27|  1.11k|void *readstat_realloc(void *ptr, size_t len) {
   28|  1.11k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  2.22k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (28:9): [True: 0, False: 1.11k]
  |  Branch (28:34): [True: 0, False: 1.11k]
  ------------------
   29|      0|        if (ptr)
  ------------------
  |  Branch (29:13): [True: 0, False: 0]
  ------------------
   30|      0|            free(ptr);
   31|      0|        return NULL;
   32|      0|    }
   33|  1.11k|    return realloc(ptr, len);
   34|  1.11k|}

readstat_parser_init:
    6|  1.53k|readstat_parser_t *readstat_parser_init(void) {
    7|  1.53k|    readstat_parser_t *parser = calloc(1, sizeof(readstat_parser_t));
    8|  1.53k|    parser->io = calloc(1, sizeof(readstat_io_t));
    9|  1.53k|    if (unistd_io_init(parser) != READSTAT_OK) {
  ------------------
  |  Branch (9:9): [True: 0, False: 1.53k]
  ------------------
   10|      0|        readstat_parser_free(parser);
   11|      0|        return NULL;
   12|      0|    }
   13|  1.53k|    parser->output_encoding = "UTF-8";
   14|  1.53k|    return parser;
   15|  1.53k|}
readstat_parser_free:
   17|  1.53k|void readstat_parser_free(readstat_parser_t *parser) {
   18|  1.53k|    if (parser) {
  ------------------
  |  Branch (18:9): [True: 1.53k, False: 0]
  ------------------
   19|  1.53k|        if (parser->io) {
  ------------------
  |  Branch (19:13): [True: 1.53k, False: 0]
  ------------------
   20|       |            readstat_set_io_ctx(parser, NULL);
   21|  1.53k|            free(parser->io);
   22|  1.53k|        }
   23|  1.53k|        free(parser);
   24|  1.53k|    }
   25|  1.53k|}
readstat_set_metadata_handler:
   27|  1.53k|readstat_error_t readstat_set_metadata_handler(readstat_parser_t *parser, readstat_metadata_handler metadata_handler) {
   28|  1.53k|    parser->handlers.metadata = metadata_handler;
   29|  1.53k|    return READSTAT_OK;
   30|  1.53k|}
readstat_set_note_handler:
   32|  1.53k|readstat_error_t readstat_set_note_handler(readstat_parser_t *parser, readstat_note_handler note_handler) {
   33|  1.53k|    parser->handlers.note = note_handler;
   34|  1.53k|    return READSTAT_OK;
   35|  1.53k|}
readstat_set_variable_handler:
   37|  1.53k|readstat_error_t readstat_set_variable_handler(readstat_parser_t *parser, readstat_variable_handler variable_handler) {
   38|  1.53k|    parser->handlers.variable = variable_handler;
   39|  1.53k|    return READSTAT_OK;
   40|  1.53k|}
readstat_set_value_handler:
   42|  1.53k|readstat_error_t readstat_set_value_handler(readstat_parser_t *parser, readstat_value_handler value_handler) {
   43|  1.53k|    parser->handlers.value = value_handler;
   44|  1.53k|    return READSTAT_OK;
   45|  1.53k|}
readstat_set_value_label_handler:
   47|  1.53k|readstat_error_t readstat_set_value_label_handler(readstat_parser_t *parser, readstat_value_label_handler label_handler) {
   48|  1.53k|    parser->handlers.value_label = label_handler;
   49|  1.53k|    return READSTAT_OK;
   50|  1.53k|}
readstat_set_fweight_handler:
   62|  1.53k|readstat_error_t readstat_set_fweight_handler(readstat_parser_t *parser, readstat_fweight_handler fweight_handler) {
   63|  1.53k|    parser->handlers.fweight = fweight_handler;
   64|  1.53k|    return READSTAT_OK;
   65|  1.53k|}
readstat_set_open_handler:
   67|  3.06k|readstat_error_t readstat_set_open_handler(readstat_parser_t *parser, readstat_open_handler open_handler) {
   68|  3.06k|    parser->io->open = open_handler;
   69|  3.06k|    return READSTAT_OK;
   70|  3.06k|}
readstat_set_close_handler:
   72|  3.06k|readstat_error_t readstat_set_close_handler(readstat_parser_t *parser, readstat_close_handler close_handler) {
   73|  3.06k|    parser->io->close = close_handler;
   74|  3.06k|    return READSTAT_OK;
   75|  3.06k|}
readstat_set_seek_handler:
   77|  3.06k|readstat_error_t readstat_set_seek_handler(readstat_parser_t *parser, readstat_seek_handler seek_handler) {
   78|  3.06k|    parser->io->seek = seek_handler;
   79|  3.06k|    return READSTAT_OK;
   80|  3.06k|}
readstat_set_read_handler:
   82|  3.06k|readstat_error_t readstat_set_read_handler(readstat_parser_t *parser, readstat_read_handler read_handler) {
   83|  3.06k|    parser->io->read = read_handler;
   84|  3.06k|    return READSTAT_OK;
   85|  3.06k|}
readstat_set_update_handler:
   87|  3.06k|readstat_error_t readstat_set_update_handler(readstat_parser_t *parser, readstat_update_handler update_handler) {
   88|  3.06k|    parser->io->update = update_handler;
   89|  3.06k|    return READSTAT_OK;
   90|  3.06k|}
readstat_set_io_ctx:
   92|  4.59k|readstat_error_t readstat_set_io_ctx(readstat_parser_t *parser, void *io_ctx) {
   93|  4.59k|    if (parser->io->io_ctx_needs_free) {
  ------------------
  |  Branch (93:9): [True: 1.53k, False: 3.06k]
  ------------------
   94|  1.53k|        free(parser->io->io_ctx);
   95|  1.53k|    }
   96|       |
   97|  4.59k|    parser->io->io_ctx = io_ctx;
   98|  4.59k|    parser->io->io_ctx_needs_free = 0;
   99|       |
  100|  4.59k|    return READSTAT_OK;
  101|  4.59k|}

memreverse:
   22|  90.2k|void memreverse(void *intp_void, int l) {
   23|  90.2k|    if (!machine_is_little_endian())
  ------------------
  |  Branch (23:9): [True: 0, False: 90.2k]
  ------------------
   24|      0|        return;
   25|       |
   26|  90.2k|    int i,j;
   27|  90.2k|    char save;
   28|  90.2k|    char *intp = (char *)intp_void;
   29|       |
   30|  90.2k|    j = l/2;
   31|   270k|    for (i=0;i<j;i++) {
  ------------------
  |  Branch (31:14): [True: 180k, False: 90.2k]
  ------------------
   32|   180k|        save = intp[i];
   33|   180k|        intp[i] = intp[l-i-1];
   34|   180k|        intp[l-i-1] = save;
   35|   180k|    }
   36|  90.2k|}
cnxptiee:
   39|  39.6k|{
   40|  39.6k|    unsigned char *from = (unsigned char *)from_bytes;
   41|  39.6k|    unsigned char *to = (unsigned char *)to_bytes;
   42|  39.6k|    unsigned char temp[8];
   43|  39.6k|    int i;
   44|       |
   45|  39.6k|    if (fromtype == CN_TYPE_NATIVE) {
  ------------------
  |  |    1|  39.6k|#define CN_TYPE_NATIVE 0
  ------------------
  |  Branch (45:9): [True: 0, False: 39.6k]
  ------------------
   46|      0|        fromtype = FLOATREP;
  ------------------
  |  |   18|      0|#define FLOATREP get_native()
  ------------------
   47|      0|    }
   48|  39.6k|    switch(fromtype) {
   49|      0|        case CN_TYPE_IEEEL :
  ------------------
  |  |    4|      0|#define CN_TYPE_IEEEL 3
  ------------------
  |  Branch (49:9): [True: 0, False: 39.6k]
  ------------------
   50|      0|            if (totype == CN_TYPE_IEEEL)
  ------------------
  |  |    4|      0|#define CN_TYPE_IEEEL 3
  ------------------
  |  Branch (50:17): [True: 0, False: 0]
  ------------------
   51|      0|                break;
   52|      0|            for (i=7;i>=0;i--) {
  ------------------
  |  Branch (52:22): [True: 0, False: 0]
  ------------------
   53|      0|                temp[7-i] = from[i];
   54|      0|            }
   55|      0|            from = temp;
   56|      0|            fromtype = CN_TYPE_IEEEB;
  ------------------
  |  |    3|      0|#define CN_TYPE_IEEEB 2
  ------------------
   57|       |            /* Break intentionally omitted. */
   58|      0|        case CN_TYPE_IEEEB :
  ------------------
  |  |    3|      0|#define CN_TYPE_IEEEB 2
  ------------------
  |  Branch (58:9): [True: 0, False: 39.6k]
  ------------------
   59|       |            /* Break intentionally omitted. */
   60|  39.6k|        case CN_TYPE_XPORT :
  ------------------
  |  |    2|  39.6k|#define CN_TYPE_XPORT 1
  ------------------
  |  Branch (60:9): [True: 39.6k, False: 0]
  ------------------
   61|  39.6k|            break;
   62|      0|        default:
  ------------------
  |  Branch (62:9): [True: 0, False: 39.6k]
  ------------------
   63|      0|            return(-1);
   64|  39.6k|    }
   65|  39.6k|    if (totype == CN_TYPE_NATIVE) {
  ------------------
  |  |    1|  39.6k|#define CN_TYPE_NATIVE 0
  ------------------
  |  Branch (65:9): [True: 39.6k, False: 0]
  ------------------
   66|  39.6k|        totype = FLOATREP;
  ------------------
  |  |   18|  39.6k|#define FLOATREP get_native()
  ------------------
   67|  39.6k|    }
   68|  39.6k|    switch(totype) {
   69|      0|        case CN_TYPE_XPORT :
  ------------------
  |  |    2|      0|#define CN_TYPE_XPORT 1
  ------------------
  |  Branch (69:9): [True: 0, False: 39.6k]
  ------------------
   70|      0|        case CN_TYPE_IEEEB :
  ------------------
  |  |    3|      0|#define CN_TYPE_IEEEB 2
  ------------------
  |  Branch (70:9): [True: 0, False: 39.6k]
  ------------------
   71|  39.6k|        case CN_TYPE_IEEEL :
  ------------------
  |  |    4|  39.6k|#define CN_TYPE_IEEEL 3
  ------------------
  |  Branch (71:9): [True: 39.6k, False: 0]
  ------------------
   72|  39.6k|            break;
   73|      0|        default:
  ------------------
  |  Branch (73:9): [True: 0, False: 39.6k]
  ------------------
   74|      0|            return(-2);
   75|  39.6k|    }
   76|  39.6k|    if (fromtype == totype) {
  ------------------
  |  Branch (76:9): [True: 0, False: 39.6k]
  ------------------
   77|      0|        memcpy(to,from,8);
   78|      0|        return(0);
   79|      0|    }
   80|  39.6k|    switch(fromtype) {
  ------------------
  |  Branch (80:12): [True: 39.6k, False: 0]
  ------------------
   81|      0|        case CN_TYPE_IEEEB :
  ------------------
  |  |    3|      0|#define CN_TYPE_IEEEB 2
  ------------------
  |  Branch (81:9): [True: 0, False: 39.6k]
  ------------------
   82|      0|            if (totype == CN_TYPE_XPORT)
  ------------------
  |  |    2|      0|#define CN_TYPE_XPORT 1
  ------------------
  |  Branch (82:17): [True: 0, False: 0]
  ------------------
   83|      0|                ieee2xpt(from,to);
   84|      0|            else memcpy(to,from,8);
   85|      0|            break;
   86|  39.6k|        case CN_TYPE_XPORT :
  ------------------
  |  |    2|  39.6k|#define CN_TYPE_XPORT 1
  ------------------
  |  Branch (86:9): [True: 39.6k, False: 0]
  ------------------
   87|  39.6k|            xpt2ieee(from,to);
   88|  39.6k|            break;
   89|  39.6k|    }
   90|  39.6k|    if (totype == CN_TYPE_IEEEL) {
  ------------------
  |  |    4|  39.6k|#define CN_TYPE_IEEEL 3
  ------------------
  |  Branch (90:9): [True: 39.6k, False: 0]
  ------------------
   91|  39.6k|        memcpy(temp,to,8);
   92|   356k|        for (i=7;i>=0;i--) {
  ------------------
  |  Branch (92:18): [True: 317k, False: 39.6k]
  ------------------
   93|   317k|            to[7-i] = temp[i];
   94|   317k|        }
   95|  39.6k|    }
   96|  39.6k|    return(0);
   97|  39.6k|}
get_native:
   99|  39.6k|int get_native(void) {
  100|  39.6k|    static unsigned char float_reps[][8] = {
  101|  39.6k|        {0x41,0x10,0x00,0x00,0x00,0x00,0x00,0x00},
  102|  39.6k|        {0x3f,0xf0,0x00,0x00,0x00,0x00,0x00,0x00},
  103|  39.6k|        {0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f}
  104|  39.6k|    };
  105|       |
  106|  39.6k|    static double one = 1.00;
  107|       |
  108|  39.6k|    int i,j;
  109|  39.6k|    j = sizeof(float_reps)/8;
  110|   118k|    for (i=0;i<j;i++)  {
  ------------------
  |  Branch (110:14): [True: 118k, False: 0]
  ------------------
  111|   118k|        if (memcmp(&one,float_reps+i,8) == 0)
  ------------------
  |  Branch (111:13): [True: 39.6k, False: 79.2k]
  ------------------
  112|  39.6k|            return(i+1);
  113|   118k|    }
  114|      0|    return(-1);
  115|  39.6k|}
ieee.c:xpt2ieee:
  117|  39.6k|void xpt2ieee(unsigned char *xport, unsigned char *ieee) {
  118|  39.6k|    char temp[8];
  119|  39.6k|    register int shift;
  120|  39.6k|    register int nib;
  121|  39.6k|    uint32_t ieee1,ieee2;
  122|  39.6k|    uint32_t xport1 = 0;
  123|  39.6k|    uint32_t xport2 = 0;
  124|       |
  125|  39.6k|    memcpy(temp,xport,8);
  126|  39.6k|    memset(ieee,0,8);
  127|       |
  128|  39.6k|    if (*temp && memcmp(temp+1,ieee,7) == 0) {
  ------------------
  |  Branch (128:9): [True: 5.71k, False: 33.9k]
  |  Branch (128:18): [True: 234, False: 5.47k]
  ------------------
  129|    234|        ieee[0] = ieee[1] = 0xff;
  130|    234|        ieee[2] = ~(*temp);
  131|    234|        return;
  132|    234|    }
  133|       |
  134|  39.4k|    memcpy(&xport1,temp,sizeof(uint32_t));
  135|  39.4k|    memreverse(&xport1,sizeof(uint32_t));
  136|  39.4k|    memcpy(&xport2,temp+4,sizeof(uint32_t));
  137|  39.4k|    memreverse(&xport2,sizeof(uint32_t));
  138|       |
  139|       |    /***************************************************************/
  140|       |    /* Translate IBM format floating point numbers into IEEE */
  141|       |    /* format floating point numbers. */
  142|       |    /* */
  143|       |    /* IEEE format: */
  144|       |    /* */
  145|       |    /* 6 5 0 */
  146|       |    /* 3 1 0 */
  147|       |    /* */
  148|       |    /* SEEEEEEEEEEEMMMM ............ MMMM */
  149|       |    /* */
  150|       |    /* Sign bit, 11 bits exponent, 52 bit fraction. Exponent is */
  151|       |    /* excess 1023. The fraction is multiplied by a power of 2 of */
  152|       |
  153|       |    /* the actual exponent. Normalized floating point numbers are */
  154|       |    /* represented with the binary point immediately to the left */
  155|       |    /* of the fraction with an implied "1" to the left of the */
  156|       |    /* binary point. */
  157|       |    /* */
  158|       |    /* IBM format: */
  159|       |    /* */
  160|       |    /* 6 5 0 */
  161|       |    /* 3 1 0 */
  162|       |    /* */
  163|       |    /* SEEEEEEEMMMM ......... MMMM */
  164|       |    /* */
  165|       |    /* Sign bit, 7 bit exponent, 56 bit fraction. Exponent is */
  166|       |    /* excess 64. The fraction is multiplied bya power of 16 of */
  167|       |    /* the actual exponent. Normalized floating point numbers are */
  168|       |    /* represented with the radix point immediately to the left of*/
  169|       |    /* the high order hex fraction digit. */
  170|       |    /* */
  171|       |    /* How do you translate from IBM format to IEEE? */
  172|       |    /* */
  173|       |    /* Translating back to ieee format from ibm is easier than */
  174|       |    /* going the other way. You lose at most, 3 bits of fraction, */
  175|       |    /* but nothing can be done about that. The only tricky parts */
  176|       |    /* are setting up the correct binary exponent from the ibm */
  177|       |    /* hex exponent, and removing the implicit "1" bit of the ieee*/
  178|       |    /* fraction (see vzctdbl). We must shift down the high order */
  179|       |    /* nibble of the ibm fraction until it is 1. This is the */
  180|       |    /* implicit 1. The bit is then cleared and the exponent */
  181|       |    /* adjusted by the number of positions shifted. A more */
  182|       |    /* thorough discussion is in vzctdbl.c. */
  183|       |
  184|  39.4k|    if ((xport1 & 0x7fffffff) == 0x7fffffff && xport2 == 0xffffffff) {
  ------------------
  |  Branch (184:9): [True: 678, False: 38.7k]
  |  Branch (184:48): [True: 194, False: 484]
  ------------------
  185|    194|        ieee1 = (xport1 & 0x80000000) | 0x7ff00000;
  186|    194|        ieee2 = 0;
  187|    194|        goto doret;
  188|    194|    }
  189|       |
  190|       |    /* Get the first half of the ibm number without the exponent */
  191|       |    /* into the ieee number */
  192|  39.2k|    ieee1 = xport1 & 0x00ffffff;
  193|       |
  194|       |    /* get the second half of the ibm number into the second half */
  195|       |    /* of the ieee number . If both halves were 0. then just */
  196|       |    /* return since the ieee number is zero. */
  197|  39.2k|    if ((!(ieee2 = xport2)) && !xport1)
  ------------------
  |  Branch (197:9): [True: 35.0k, False: 4.11k]
  |  Branch (197:32): [True: 33.6k, False: 1.42k]
  ------------------
  198|  33.6k|        return;
  199|       |
  200|       |    /* The fraction bit to the left of the binary point in the */
  201|       |    /* ieee format was set and the number was shifted 0, 1, 2, or */
  202|       |    /* 3 places. This will tell us how to adjust the ibm exponent */
  203|       |    /* to be a power of 2 ieee exponent and how to shift the */
  204|       |    /* fraction bits to restore the correct magnitude. */
  205|       |
  206|  5.53k|    if ((nib = (int)xport1) & 0x00800000) {
  ------------------
  |  Branch (206:9): [True: 2.90k, False: 2.63k]
  ------------------
  207|  2.90k|        shift = 3;
  208|  2.90k|    } else if (nib & 0x00400000) {
  ------------------
  |  Branch (208:16): [True: 713, False: 1.92k]
  ------------------
  209|    713|        shift = 2;
  210|  1.92k|    } else if (nib & 0x00200000) {
  ------------------
  |  Branch (210:16): [True: 1.46k, False: 456]
  ------------------
  211|  1.46k|        shift = 1;
  212|  1.46k|    } else {
  213|    456|        shift = 0;
  214|    456|    }
  215|       |
  216|  5.53k|    if (shift) {
  ------------------
  |  Branch (216:9): [True: 5.08k, False: 456]
  ------------------
  217|       |        /* shift the ieee number down the correct number of places */
  218|       |        /* then set the second half of the ieee number to be the */
  219|       |        /* second half of the ibm number shifted appropriately, */
  220|       |        /* ored with the bits from the first half that would have */
  221|       |        /* been shifted in if we could shift a double. All we are */
  222|       |        /* worried about are the low order 3 bits of the first */
  223|       |        /* half since we're only shifting by 1, 2, or 3. */
  224|  5.08k|        ieee1 >>= shift;
  225|  5.08k|        ieee2 = (xport2 >> shift) |
  226|  5.08k|            ((xport1 & 0x00000007) << (29 + (3 - shift)));
  227|  5.08k|    }
  228|       |
  229|       |    /* clear the 1 bit to the left of the binary point */
  230|  5.53k|    ieee1 &= 0xffefffff;
  231|       |
  232|       |    /* set the exponent of the ieee number to be the actual */
  233|       |    /* exponent plus the shift count + 1023. Or this into the */
  234|       |    /* first half of the ieee number. The ibm exponent is excess */
  235|       |    /* 64 but is adjusted by 65 since during conversion to ibm */
  236|       |    /* format the exponent is incremented by 1 and the fraction */
  237|       |    /* bits left 4 positions to the right of the radix point. */
  238|  5.53k|    ieee1 |=
  239|  5.53k|        (((((int32_t)(*temp & 0x7f) - 65) * 4) + shift + 1023) << 20) |
  240|  5.53k|        (xport1 & 0x80000000);
  241|       |
  242|  5.73k|doret:
  243|  5.73k|    memreverse(&ieee1,sizeof(uint32_t));
  244|  5.73k|    memcpy(ieee,&ieee1,sizeof(uint32_t));
  245|  5.73k|    memreverse(&ieee2,sizeof(uint32_t));
  246|  5.73k|    memcpy(ieee+4,&ieee2,sizeof(uint32_t));
  247|  5.73k|    return;
  248|  5.53k|}

sas_validate_tag:
  507|  34.3k|readstat_error_t sas_validate_tag(char tag) {
  508|  34.3k|    if (tag == '_' || (tag >= 'A' && tag <= 'Z'))
  ------------------
  |  Branch (508:9): [True: 194, False: 34.1k]
  |  Branch (508:24): [True: 410, False: 33.6k]
  |  Branch (508:38): [True: 203, False: 207]
  ------------------
  509|    397|        return READSTAT_OK;
  510|       |
  511|  33.9k|    return READSTAT_ERROR_TAGGED_VALUE_IS_OUT_OF_RANGE;
  512|  34.3k|}

xport_namestr_bswap:
   10|  96.7k|void xport_namestr_bswap(xport_namestr_t *namestr) {
   11|  96.7k|    if (!machine_is_little_endian())
  ------------------
  |  Branch (11:9): [True: 0, False: 96.7k]
  ------------------
   12|      0|        return;
   13|       |
   14|  96.7k|    namestr->ntype = byteswap2(namestr->ntype);
   15|  96.7k|    namestr->nhfun = byteswap2(namestr->nhfun);
   16|  96.7k|    namestr->nlng = byteswap2(namestr->nlng);
   17|  96.7k|    namestr->nvar0 = byteswap2(namestr->nvar0);
   18|       |
   19|  96.7k|    namestr->nfl = byteswap2(namestr->nfl);
   20|  96.7k|    namestr->nfd = byteswap2(namestr->nfd);
   21|  96.7k|    namestr->nfj = byteswap2(namestr->nfj);
   22|       |
   23|  96.7k|    namestr->nifl = byteswap2(namestr->nifl);
   24|  96.7k|    namestr->nifd = byteswap2(namestr->nifd);
   25|  96.7k|    namestr->npos = byteswap4(namestr->npos);
   26|       |
   27|  96.7k|    namestr->labeln  = byteswap2(namestr->labeln);
   28|  96.7k|}

readstat_parse_xport:
  703|  1.53k|readstat_error_t readstat_parse_xport(readstat_parser_t *parser, const char *path, void *user_ctx) {
  704|  1.53k|    readstat_error_t retval = READSTAT_OK;
  705|  1.53k|    readstat_io_t *io = parser->io;
  706|       |
  707|  1.53k|    xport_ctx_t *ctx = xport_ctx_init();
  708|  1.53k|    ctx->handle = parser->handlers;
  709|  1.53k|    ctx->input_encoding = parser->input_encoding;
  710|  1.53k|    ctx->output_encoding = parser->output_encoding;
  711|  1.53k|    ctx->user_ctx = user_ctx;
  712|  1.53k|    ctx->io = io;
  713|  1.53k|    ctx->row_limit = parser->row_limit;
  714|  1.53k|    if (parser->row_offset > 0)
  ------------------
  |  Branch (714:9): [True: 0, False: 1.53k]
  ------------------
  715|      0|        ctx->row_offset = parser->row_offset;
  716|       |
  717|  1.53k|    if (io->open(path, io->io_ctx) == -1) {
  ------------------
  |  Branch (717:9): [True: 0, False: 1.53k]
  ------------------
  718|      0|        retval = READSTAT_ERROR_OPEN;
  719|      0|        goto cleanup;
  720|      0|    }
  721|       |
  722|  1.53k|    if ((ctx->file_size = io->seek(0, READSTAT_SEEK_END, io->io_ctx)) == -1) {
  ------------------
  |  Branch (722:9): [True: 0, False: 1.53k]
  ------------------
  723|      0|        retval = READSTAT_ERROR_SEEK;
  724|      0|        goto cleanup;
  725|      0|    }
  726|       |
  727|  1.53k|    if (io->seek(0, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (727:9): [True: 0, False: 1.53k]
  ------------------
  728|      0|        retval = READSTAT_ERROR_SEEK;
  729|      0|        goto cleanup;
  730|      0|    }
  731|       |
  732|  1.53k|    if (ctx->input_encoding && ctx->output_encoding && strcmp(ctx->input_encoding, ctx->output_encoding) != 0) {
  ------------------
  |  Branch (732:9): [True: 0, False: 1.53k]
  |  Branch (732:32): [True: 0, False: 0]
  |  Branch (732:56): [True: 0, False: 0]
  ------------------
  733|      0|        iconv_t converter = iconv_open(ctx->output_encoding, ctx->input_encoding);
  734|      0|        if (converter == (iconv_t)-1) {
  ------------------
  |  Branch (734:13): [True: 0, False: 0]
  ------------------
  735|      0|            retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
  736|      0|            goto cleanup;
  737|      0|        }
  738|      0|        ctx->converter = converter;
  739|      0|    }
  740|       |
  741|  1.53k|    retval = xport_read_library_record(ctx);
  742|  1.53k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (742:9): [True: 96, False: 1.43k]
  ------------------
  743|     96|        goto cleanup;
  744|       |
  745|  1.43k|    retval = xport_skip_record(ctx);
  746|  1.43k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (746:9): [True: 11, False: 1.42k]
  ------------------
  747|     11|        goto cleanup;
  748|       |
  749|  1.42k|    retval = xport_read_timestamp_record(ctx);
  750|  1.42k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (750:9): [True: 12, False: 1.41k]
  ------------------
  751|     12|        goto cleanup;
  752|       |
  753|  1.41k|    retval = xport_expect_header_record(ctx, "MEMBER", "MEMBV8");
  754|  1.41k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (754:9): [True: 147, False: 1.26k]
  ------------------
  755|    147|        goto cleanup;
  756|       |
  757|  1.26k|    retval = xport_expect_header_record(ctx, "DSCRPTR", "DSCPTV8");
  758|  1.26k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (758:9): [True: 21, False: 1.24k]
  ------------------
  759|     21|        goto cleanup;
  760|       |
  761|  1.24k|    retval = xport_read_table_name_record(ctx);
  762|  1.24k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (762:9): [True: 13, False: 1.23k]
  ------------------
  763|     13|        goto cleanup;
  764|       |
  765|  1.23k|    retval = xport_read_file_label_record(ctx);
  766|  1.23k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (766:9): [True: 29, False: 1.20k]
  ------------------
  767|     29|        goto cleanup;
  768|       |
  769|  1.20k|    retval = xport_read_namestr_header_record(ctx);
  770|  1.20k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (770:9): [True: 154, False: 1.04k]
  ------------------
  771|    154|        goto cleanup;
  772|       |
  773|  1.04k|    retval = xport_read_variables(ctx);
  774|  1.04k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (774:9): [True: 476, False: 572]
  ------------------
  775|    476|        goto cleanup;
  776|       |
  777|    572|    if (ctx->row_length) {
  ------------------
  |  Branch (777:9): [True: 562, False: 10]
  ------------------
  778|    562|        retval = xport_read_data(ctx);
  779|    562|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (779:13): [True: 7, False: 555]
  ------------------
  780|      7|            goto cleanup;
  781|    562|    }
  782|       |
  783|  1.53k|cleanup:
  784|  1.53k|    io->close(io->io_ctx);
  785|  1.53k|    xport_ctx_free(ctx);
  786|       |
  787|  1.53k|    return retval;
  788|    572|}
readstat_xport_read.c:xport_ctx_init:
   48|  1.53k|static xport_ctx_t *xport_ctx_init(void) {
   49|  1.53k|    xport_ctx_t *ctx = calloc(1, sizeof(xport_ctx_t));
   50|  1.53k|    return ctx;
   51|  1.53k|}
readstat_xport_read.c:xport_read_library_record:
  183|  1.53k|static readstat_error_t xport_read_library_record(xport_ctx_t *ctx) {
  184|  1.53k|    xport_header_record_t xrecord;
  185|  1.53k|    readstat_error_t retval = xport_read_header_record(ctx, &xrecord);
  186|  1.53k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (186:9): [True: 23, False: 1.50k]
  ------------------
  187|     23|        goto cleanup;
  188|       |
  189|  1.50k|    if (strcmp(xrecord.name, "LIBRARY") == 0) {
  ------------------
  |  Branch (189:9): [True: 256, False: 1.25k]
  ------------------
  190|    256|        ctx->version = 5;
  191|  1.25k|    } else if (strcmp(xrecord.name, "LIBV8") == 0) {
  ------------------
  |  Branch (191:16): [True: 1.17k, False: 73]
  ------------------
  192|  1.17k|        ctx->version = 8;
  193|  1.17k|    } else {
  194|     73|        retval = READSTAT_ERROR_UNSUPPORTED_FILE_FORMAT_VERSION;
  195|     73|        goto cleanup;
  196|     73|    }
  197|       |
  198|  1.53k|cleanup:
  199|  1.53k|    return retval;
  200|  1.50k|}
readstat_xport_read.c:xport_read_header_record:
  106|  6.42k|static readstat_error_t xport_read_header_record(xport_ctx_t *ctx, xport_header_record_t *xrecord) {
  107|  6.42k|    char line[LINE_LEN+1];
  108|  6.42k|    readstat_error_t retval = READSTAT_OK;
  109|       |
  110|  6.42k|    retval = xport_read_record(ctx, line);
  111|  6.42k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (111:9): [True: 155, False: 6.26k]
  ------------------
  112|    155|        return retval;
  113|       |
  114|  6.26k|    memset(xrecord, 0, sizeof(xport_header_record_t));
  115|  6.26k|    int matches = sscanf(line,
  116|  6.26k|            "HEADER RECORD*******%8s HEADER RECORD!!!!!!!"
  117|  6.26k|            "%05d%05d%05d" "%05d%05d%05d", xrecord->name,
  118|  6.26k|            &xrecord->num1, &xrecord->num2, &xrecord->num3,
  119|  6.26k|            &xrecord->num4, &xrecord->num5, &xrecord->num6);
  120|       |
  121|  6.26k|    if (matches < 2) {
  ------------------
  |  Branch (121:9): [True: 15, False: 6.25k]
  ------------------
  122|     15|        return READSTAT_ERROR_PARSE;
  123|     15|    }
  124|       |
  125|  6.25k|    return READSTAT_OK;
  126|  6.26k|}
readstat_xport_read.c:xport_read_record:
   96|  10.3k|static readstat_error_t xport_read_record(xport_ctx_t *ctx, char *record) {
   97|  10.3k|    ssize_t bytes_read = read_bytes(ctx, record, LINE_LEN);
  ------------------
  |  |   16|  10.3k|#define LINE_LEN        80
  ------------------
   98|  10.3k|    if (bytes_read < LINE_LEN)
  ------------------
  |  |   16|  10.3k|#define LINE_LEN        80
  ------------------
  |  Branch (98:9): [True: 209, False: 10.1k]
  ------------------
   99|    209|        return READSTAT_ERROR_READ;
  100|       |
  101|  10.1k|    record[LINE_LEN] = '\0';
  ------------------
  |  |   16|  10.1k|#define LINE_LEN        80
  ------------------
  102|       |
  103|  10.1k|    return READSTAT_OK;
  104|  10.3k|}
readstat_xport_read.c:read_bytes:
   69|   154k|static ssize_t read_bytes(xport_ctx_t *ctx, void *dst, size_t dst_len) {
   70|   154k|    readstat_io_t *io = (readstat_io_t *)ctx->io;
   71|   154k|    return io->read(dst, dst_len, io->io_ctx);
   72|   154k|}
readstat_xport_read.c:xport_skip_record:
   74|  1.43k|static readstat_error_t xport_skip_record(xport_ctx_t *ctx) {
   75|  1.43k|    readstat_io_t *io = (readstat_io_t *)ctx->io;
   76|  1.43k|    if (io->seek(LINE_LEN, READSTAT_SEEK_CUR, io->io_ctx) == -1)
  ------------------
  |  |   16|  1.43k|#define LINE_LEN        80
  ------------------
  |  Branch (76:9): [True: 11, False: 1.42k]
  ------------------
   77|     11|        return READSTAT_ERROR_SEEK;
   78|       |
   79|  1.42k|    return READSTAT_OK;
   80|  1.43k|}
readstat_xport_read.c:xport_read_timestamp_record:
  202|  1.42k|static readstat_error_t xport_read_timestamp_record(xport_ctx_t *ctx) {
  203|  1.42k|    char line[LINE_LEN+1];
  204|  1.42k|    readstat_error_t retval = READSTAT_OK;
  205|  1.42k|    struct tm ts = { .tm_isdst = -1 };
  206|  1.42k|    char month[4];
  207|  1.42k|    int i;
  208|       |
  209|  1.42k|    retval = xport_read_record(ctx, line);
  210|  1.42k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (210:9): [True: 12, False: 1.41k]
  ------------------
  211|     12|        goto cleanup;
  212|       |
  213|  1.41k|    sscanf(line,
  214|  1.41k|            "%02d%3s%02d:%02d:%02d:%02d",
  215|  1.41k|            &ts.tm_mday, month, &ts.tm_year, &ts.tm_hour, &ts.tm_min, &ts.tm_sec);
  216|       |
  217|  14.0k|    for (i=0; i<sizeof(_xport_months)/sizeof(_xport_months[0]); i++) {
  ------------------
  |  Branch (217:15): [True: 13.1k, False: 970]
  ------------------
  218|  13.1k|        if (strcmp(month, _xport_months[i]) == 0) {
  ------------------
  |  Branch (218:13): [True: 442, False: 12.6k]
  ------------------
  219|    442|            ts.tm_mon = i;
  220|    442|            break;
  221|    442|        }
  222|  13.1k|    }
  223|       |
  224|  1.41k|    if (ts.tm_year < 60) {
  ------------------
  |  Branch (224:9): [True: 1.39k, False: 15]
  ------------------
  225|  1.39k|        ts.tm_year += 100;
  226|  1.39k|    }
  227|       |
  228|  1.41k|    ctx->timestamp = mktime(&ts);
  229|       |
  230|  1.42k|cleanup:
  231|  1.42k|    return retval;
  232|  1.41k|}
readstat_xport_read.c:xport_expect_header_record:
  129|  2.80k|        const char *v5_name, const char *v8_name) {
  130|  2.80k|    readstat_error_t retval = READSTAT_OK;
  131|  2.80k|    xport_header_record_t xrecord;
  132|       |
  133|  2.80k|    retval = xport_read_header_record(ctx, &xrecord);
  134|  2.80k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (134:9): [True: 107, False: 2.69k]
  ------------------
  135|    107|        goto cleanup;
  136|       |
  137|  2.69k|    if (ctx->version == 5 && strcmp(xrecord.name, v5_name) != 0) {
  ------------------
  |  Branch (137:9): [True: 467, False: 2.22k]
  |  Branch (137:30): [True: 63, False: 404]
  ------------------
  138|     63|        retval = READSTAT_ERROR_PARSE;
  139|     63|        goto cleanup;
  140|  2.63k|    } else if (ctx->version == 8 && strcmp(xrecord.name, v8_name) != 0) {
  ------------------
  |  Branch (140:16): [True: 2.22k, False: 404]
  |  Branch (140:37): [True: 64, False: 2.16k]
  ------------------
  141|     64|        retval = READSTAT_ERROR_PARSE;
  142|     64|        goto cleanup;
  143|     64|    }
  144|       |
  145|  2.80k|cleanup:
  146|  2.80k|    return retval;
  147|  2.69k|}
readstat_xport_read.c:xport_read_table_name_record:
  149|  1.24k|static readstat_error_t xport_read_table_name_record(xport_ctx_t *ctx) {
  150|  1.24k|    char line[LINE_LEN+1];
  151|  1.24k|    readstat_error_t retval = READSTAT_OK;
  152|       |
  153|  1.24k|    retval = xport_read_record(ctx, line);
  154|  1.24k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (154:9): [True: 13, False: 1.23k]
  ------------------
  155|     13|        goto cleanup;
  156|       |
  157|  1.23k|    retval = readstat_convert(ctx->table_name, sizeof(ctx->table_name), &line[8],
  158|  1.23k|            ctx->version == 5 ? 8 : 32, ctx->converter);
  ------------------
  |  Branch (158:13): [True: 164, False: 1.06k]
  ------------------
  159|  1.23k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (159:9): [True: 0, False: 1.23k]
  ------------------
  160|      0|        goto cleanup;
  161|       |
  162|  1.24k|cleanup:
  163|  1.24k|    return retval;
  164|  1.23k|}
readstat_xport_read.c:xport_read_file_label_record:
  166|  1.23k|static readstat_error_t xport_read_file_label_record(xport_ctx_t *ctx) {
  167|  1.23k|    char line[LINE_LEN+1];
  168|  1.23k|    readstat_error_t retval = READSTAT_OK;
  169|       |
  170|  1.23k|    retval = xport_read_record(ctx, line);
  171|  1.23k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (171:9): [True: 29, False: 1.20k]
  ------------------
  172|     29|        goto cleanup;
  173|       |
  174|  1.20k|    retval = readstat_convert(ctx->file_label, sizeof(ctx->file_label), &line[32],
  175|  1.20k|            40, ctx->converter);
  176|  1.20k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (176:9): [True: 0, False: 1.20k]
  ------------------
  177|      0|        goto cleanup;
  178|       |
  179|  1.23k|cleanup:
  180|  1.23k|    return retval;
  181|  1.20k|}
readstat_xport_read.c:xport_read_namestr_header_record:
  234|  1.20k|static readstat_error_t xport_read_namestr_header_record(xport_ctx_t *ctx) {
  235|  1.20k|    xport_header_record_t xrecord;
  236|  1.20k|    readstat_error_t retval = READSTAT_OK;
  237|       |
  238|  1.20k|    retval = xport_read_header_record(ctx, &xrecord);
  239|  1.20k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (239:9): [True: 16, False: 1.18k]
  ------------------
  240|     16|        goto cleanup;
  241|       |
  242|  1.18k|    if (ctx->version == 5 && strcmp(xrecord.name, "NAMESTR") != 0) {
  ------------------
  |  Branch (242:9): [True: 156, False: 1.03k]
  |  Branch (242:30): [True: 61, False: 95]
  ------------------
  243|     61|        retval = READSTAT_ERROR_PARSE;
  244|     61|        goto cleanup;
  245|  1.12k|    } else if (ctx->version == 8 && strcmp(xrecord.name, "NAMSTV8") != 0) {
  ------------------
  |  Branch (245:16): [True: 1.03k, False: 95]
  |  Branch (245:37): [True: 62, False: 968]
  ------------------
  246|     62|        retval = READSTAT_ERROR_PARSE;
  247|     62|        goto cleanup;
  248|     62|    }
  249|       |
  250|  1.06k|    ctx->var_count = xrecord.num2;
  251|  1.06k|    ctx->variables = readstat_calloc(ctx->var_count, sizeof(readstat_variable_t *));
  252|  1.06k|    if (ctx->variables == NULL) {
  ------------------
  |  Branch (252:9): [True: 15, False: 1.04k]
  ------------------
  253|     15|        retval = READSTAT_ERROR_MALLOC;
  254|     15|        goto cleanup;
  255|     15|    }
  256|       |
  257|  1.04k|    if (ctx->handle.metadata) {
  ------------------
  |  Branch (257:9): [True: 1.04k, False: 0]
  ------------------
  258|  1.04k|        readstat_metadata_t metadata = {
  259|  1.04k|            .row_count = -1,
  260|  1.04k|            .var_count = ctx->var_count,
  261|  1.04k|            .file_label = ctx->file_label,
  262|  1.04k|            .table_name = ctx->table_name,
  263|  1.04k|            .creation_time = ctx->timestamp,
  264|  1.04k|            .modified_time = ctx->timestamp,
  265|  1.04k|            .file_format_version = ctx->version
  266|  1.04k|        };
  267|  1.04k|        if (ctx->handle.metadata(&metadata, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (267:13): [True: 0, False: 1.04k]
  ------------------
  268|      0|            retval = READSTAT_ERROR_USER_ABORT;
  269|      0|            goto cleanup;
  270|      0|        }
  271|  1.04k|    }
  272|       |
  273|  1.20k|cleanup:
  274|  1.20k|    return retval;
  275|  1.04k|}
readstat_xport_read.c:xport_read_variables:
  458|  1.04k|static readstat_error_t xport_read_variables(xport_ctx_t *ctx) {
  459|  1.04k|    int i;
  460|  1.04k|    readstat_error_t retval = READSTAT_OK;
  461|  97.7k|    for (i=0; i<ctx->var_count; i++) {
  ------------------
  |  Branch (461:15): [True: 96.7k, False: 978]
  ------------------
  462|  96.7k|        xport_namestr_t namestr;
  463|  96.7k|        ssize_t bytes_read = read_bytes(ctx, &namestr, sizeof(xport_namestr_t));
  464|  96.7k|        if (bytes_read < sizeof(xport_namestr_t)) {
  ------------------
  |  Branch (464:13): [True: 70, False: 96.7k]
  ------------------
  465|     70|            retval = READSTAT_ERROR_READ;
  466|     70|            goto cleanup;
  467|     70|        }
  468|  96.7k|        xport_namestr_bswap(&namestr);
  469|       |
  470|  96.7k|        readstat_variable_t *variable = calloc(1, sizeof(readstat_variable_t));
  471|       |
  472|  96.7k|        variable->index = i;
  473|  96.7k|        variable->type = namestr.ntype == SAS_COLUMN_TYPE_CHR ? READSTAT_TYPE_STRING : READSTAT_TYPE_DOUBLE;
  ------------------
  |  |   90|  96.7k|#define SAS_COLUMN_TYPE_CHR  0x02
  ------------------
  |  Branch (473:26): [True: 85, False: 96.6k]
  ------------------
  474|  96.7k|        variable->storage_width = namestr.nlng;
  475|  96.7k|        variable->display_width = namestr.nfl;
  476|  96.7k|        variable->decimals = namestr.nfd;
  477|  96.7k|        variable->alignment = namestr.nfj ? READSTAT_ALIGNMENT_RIGHT : READSTAT_ALIGNMENT_LEFT;
  ------------------
  |  Branch (477:31): [True: 57.7k, False: 38.9k]
  ------------------
  478|       |
  479|  96.7k|        if (ctx->version == 5) {
  ------------------
  |  Branch (479:13): [True: 4.21k, False: 92.5k]
  ------------------
  480|  4.21k|            retval = readstat_convert(variable->name, sizeof(variable->name),
  481|  4.21k|                    namestr.nname, sizeof(namestr.nname), ctx->converter);
  482|  92.5k|        } else {
  483|  92.5k|            retval = readstat_convert(variable->name, sizeof(variable->name),
  484|  92.5k|                    namestr.longname, sizeof(namestr.longname), ctx->converter);
  485|  92.5k|        }
  486|  96.7k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (486:13): [True: 0, False: 96.7k]
  ------------------
  487|      0|            goto cleanup;
  488|       |
  489|  96.7k|        retval = readstat_convert(variable->label, sizeof(variable->label),
  490|  96.7k|                namestr.nlabel, sizeof(namestr.nlabel), ctx->converter);
  491|  96.7k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (491:13): [True: 0, False: 96.7k]
  ------------------
  492|      0|            goto cleanup;
  493|       |
  494|  96.7k|        retval = xport_construct_format(variable->format, sizeof(variable->format),
  495|  96.7k|                namestr.nform, sizeof(namestr.nform),
  496|  96.7k|                namestr.nfl, namestr.nfd);
  497|  96.7k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (497:13): [True: 0, False: 96.7k]
  ------------------
  498|      0|            goto cleanup;
  499|       |
  500|  96.7k|        retval = xport_construct_format(variable->informat, sizeof(variable->informat),
  501|  96.7k|                namestr.niform, sizeof(namestr.niform),
  502|  96.7k|                namestr.nifl, namestr.nifd);
  503|  96.7k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (503:13): [True: 0, False: 96.7k]
  ------------------
  504|      0|            goto cleanup;
  505|       |
  506|  96.7k|        ctx->variables[i] = variable;
  507|  96.7k|    }
  508|       |
  509|    978|    retval = xport_skip_rest_of_record(ctx);
  510|    978|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (510:9): [True: 25, False: 953]
  ------------------
  511|     25|        goto cleanup;
  512|       |
  513|    953|    if (ctx->version == 5) {
  ------------------
  |  Branch (513:9): [True: 65, False: 888]
  ------------------
  514|     65|        retval = xport_read_obs_header_record(ctx);
  515|     65|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (515:13): [True: 7, False: 58]
  ------------------
  516|      7|            goto cleanup;
  517|    888|    } else {
  518|    888|        xport_header_record_t xrecord;
  519|    888|        retval = xport_read_header_record(ctx, &xrecord);
  520|    888|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (520:13): [True: 24, False: 864]
  ------------------
  521|     24|            goto cleanup;
  522|       |
  523|    864|        if (strcmp(xrecord.name, "OBSV8") == 0) {
  ------------------
  |  Branch (523:13): [True: 13, False: 851]
  ------------------
  524|       |            /* void */
  525|    851|        } else if (strcmp(xrecord.name, "LABELV8") == 0) {
  ------------------
  |  Branch (525:20): [True: 152, False: 699]
  ------------------
  526|    152|            retval = xport_read_labels_v8(ctx, xrecord.num1);
  527|    699|        } else if (strcmp(xrecord.name, "LABELV9") == 0) {
  ------------------
  |  Branch (527:20): [True: 199, False: 500]
  ------------------
  528|    199|            retval = xport_read_labels_v9(ctx, xrecord.num1);
  529|    199|        }
  530|    864|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (530:13): [True: 350, False: 514]
  ------------------
  531|    350|            goto cleanup;
  532|    864|    }
  533|       |
  534|    572|    ctx->row_length = 0;
  535|       |
  536|    572|    int index_after_skipping = 0;
  537|       |
  538|  19.4k|    for (i=0; i<ctx->var_count; i++) {
  ------------------
  |  Branch (538:15): [True: 18.8k, False: 572]
  ------------------
  539|  18.8k|        readstat_variable_t *variable = ctx->variables[i];
  540|  18.8k|        variable->index_after_skipping = index_after_skipping;
  541|       |
  542|  18.8k|        int cb_retval = READSTAT_HANDLER_OK;
  543|  18.8k|        if (ctx->handle.variable) {
  ------------------
  |  Branch (543:13): [True: 18.8k, False: 0]
  ------------------
  544|  18.8k|            cb_retval = ctx->handle.variable(i, variable, variable->format, ctx->user_ctx);
  545|  18.8k|        }
  546|  18.8k|        if (cb_retval == READSTAT_HANDLER_ABORT) {
  ------------------
  |  Branch (546:13): [True: 0, False: 18.8k]
  ------------------
  547|      0|            retval = READSTAT_ERROR_USER_ABORT;
  548|      0|            goto cleanup;
  549|      0|        }
  550|  18.8k|        if (cb_retval == READSTAT_HANDLER_SKIP_VARIABLE) {
  ------------------
  |  Branch (550:13): [True: 0, False: 18.8k]
  ------------------
  551|      0|            variable->skip = 1;
  552|  18.8k|        } else {
  553|  18.8k|            index_after_skipping++;
  554|  18.8k|        }
  555|       |
  556|  18.8k|        ctx->row_length += variable->storage_width;
  557|  18.8k|    }
  558|       |
  559|  1.04k|cleanup:
  560|  1.04k|    return retval;
  561|    572|}
readstat_xport_read.c:xport_construct_format:
  282|   193k|        const char *src, size_t src_len, int width, int decimals) {
  283|   193k|    char *format = malloc(4 * src_len + 1);
  284|   193k|    if (format == NULL) return READSTAT_ERROR_MALLOC;
  ------------------
  |  Branch (284:9): [True: 0, False: 193k]
  ------------------
  285|   193k|    readstat_error_t retval = readstat_convert(format, 4 * src_len + 1, src, src_len, NULL);
  286|       |
  287|   193k|    if (retval != READSTAT_OK) {
  ------------------
  |  Branch (287:9): [True: 0, False: 193k]
  ------------------
  288|      0|        free(format);
  289|      0|        return retval;
  290|      0|    }
  291|       |
  292|   193k|    char *pos = dst;
  293|   193k|    *dst = '\0';
  294|   193k|    if (format[0]) {
  ------------------
  |  Branch (294:9): [True: 68.0k, False: 125k]
  ------------------
  295|  68.0k|        pos += snprintf(dst, dst_len, "%s", format);
  296|  68.0k|    }
  297|   193k|    if (width) {
  ------------------
  |  Branch (297:9): [True: 115k, False: 78.0k]
  ------------------
  298|   115k|        pos += snprintf(pos, dst_len-(pos-dst), "%d", width);
  299|   115k|    }
  300|   193k|    if (decimals) {
  ------------------
  |  Branch (300:9): [True: 115k, False: 78.2k]
  ------------------
  301|   115k|        pos += snprintf(pos, dst_len-(pos-dst), ".%d", decimals);
  302|   115k|    }
  303|       |
  304|   193k|    free(format);
  305|   193k|    return retval;
  306|   193k|}
readstat_xport_read.c:xport_skip_rest_of_record:
   82|  1.08k|static readstat_error_t xport_skip_rest_of_record(xport_ctx_t *ctx) {
   83|  1.08k|    readstat_io_t *io = (readstat_io_t *)ctx->io;
   84|  1.08k|    off_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
   85|  1.08k|    if (pos == -1)
  ------------------
  |  Branch (85:9): [True: 0, False: 1.08k]
  ------------------
   86|      0|        return READSTAT_ERROR_SEEK;
   87|       |
   88|  1.08k|    if (pos % LINE_LEN) {
  ------------------
  |  |   16|  1.08k|#define LINE_LEN        80
  ------------------
  |  Branch (88:9): [True: 1.01k, False: 67]
  ------------------
   89|  1.01k|        if (io->seek(LINE_LEN - (pos % LINE_LEN), READSTAT_SEEK_CUR, io->io_ctx) == -1)
  ------------------
  |  |   16|  1.01k|#define LINE_LEN        80
  ------------------
                      if (io->seek(LINE_LEN - (pos % LINE_LEN), READSTAT_SEEK_CUR, io->io_ctx) == -1)
  ------------------
  |  |   16|  1.01k|#define LINE_LEN        80
  ------------------
  |  Branch (89:13): [True: 69, False: 946]
  ------------------
   90|     69|            return READSTAT_ERROR_SEEK;
   91|  1.01k|    }
   92|       |
   93|  1.01k|    return READSTAT_OK;
   94|  1.08k|}
readstat_xport_read.c:xport_read_obs_header_record:
  277|    125|static readstat_error_t xport_read_obs_header_record(xport_ctx_t *ctx) {
  278|    125|    return xport_expect_header_record(ctx, "OBS", "OBSV8");
  279|    125|}
readstat_xport_read.c:xport_read_labels_v8:
  308|    152|static readstat_error_t xport_read_labels_v8(xport_ctx_t *ctx, int label_count) {
  309|    152|    readstat_error_t retval = READSTAT_OK;
  310|    152|    uint16_t labeldef[3];
  311|    152|    char *name = NULL;
  312|    152|    char *label = NULL;
  313|    152|    int i;
  314|    662|    for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (314:15): [True: 614, False: 48]
  ------------------
  315|    614|        int index, name_len, label_len;
  316|    614|        if (read_bytes(ctx, labeldef, sizeof(labeldef)) != sizeof(labeldef)) {
  ------------------
  |  Branch (316:13): [True: 29, False: 585]
  ------------------
  317|     29|            retval = READSTAT_ERROR_READ;
  318|     29|            goto cleanup;
  319|     29|        }
  320|       |
  321|    585|        if (machine_is_little_endian()) {
  ------------------
  |  Branch (321:13): [True: 585, False: 0]
  ------------------
  322|    585|            index = byteswap2(labeldef[0]);
  323|    585|            name_len = byteswap2(labeldef[1]);
  324|    585|            label_len = byteswap2(labeldef[2]);
  325|    585|        } else {
  326|      0|            index = labeldef[0];
  327|      0|            name_len = labeldef[1];
  328|      0|            label_len = labeldef[2];
  329|      0|        }
  330|       |
  331|    585|        if (index > ctx->var_count || index == 0) {
  ------------------
  |  Branch (331:13): [True: 17, False: 568]
  |  Branch (331:39): [True: 12, False: 556]
  ------------------
  332|     29|            retval = READSTAT_ERROR_PARSE;
  333|     29|            goto cleanup;
  334|     29|        }
  335|       |
  336|    556|        name = realloc(name, name_len + 1);
  337|    556|        label = realloc(label, label_len + 1);
  338|    556|        readstat_variable_t *variable = ctx->variables[index-1];
  339|       |
  340|    556|        if (read_bytes(ctx, name, name_len) != name_len ||
  ------------------
  |  Branch (340:13): [True: 24, False: 532]
  ------------------
  341|    532|                read_bytes(ctx, label, label_len) != label_len) {
  ------------------
  |  Branch (341:17): [True: 19, False: 513]
  ------------------
  342|     43|            retval = READSTAT_ERROR_READ;
  343|     43|            goto cleanup;
  344|     43|        }
  345|       |
  346|    513|        retval = readstat_convert(variable->name, sizeof(variable->name),
  347|    513|                name, name_len, ctx->converter);
  348|    513|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (348:13): [True: 2, False: 511]
  ------------------
  349|      2|            goto cleanup;
  350|       |
  351|    511|        retval = readstat_convert(variable->label, sizeof(variable->label),
  352|    511|                label, label_len, ctx->converter);
  353|    511|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (353:13): [True: 1, False: 510]
  ------------------
  354|      1|            goto cleanup;
  355|    511|    }
  356|       |
  357|     48|    retval = xport_skip_rest_of_record(ctx);
  358|     48|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (358:9): [True: 20, False: 28]
  ------------------
  359|     20|        goto cleanup;
  360|       |
  361|     28|    retval = xport_read_obs_header_record(ctx);
  362|     28|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (362:9): [True: 28, False: 0]
  ------------------
  363|     28|        goto cleanup;
  364|       |
  365|    152|cleanup:
  366|    152|    free(name);
  367|    152|    free(label);
  368|    152|    return retval;
  369|     28|}
readstat_xport_read.c:xport_read_labels_v9:
  371|    199|static readstat_error_t xport_read_labels_v9(xport_ctx_t *ctx, int label_count) {
  372|    199|    readstat_error_t retval = READSTAT_OK;
  373|    199|    uint16_t labeldef[5];
  374|    199|    int i;
  375|    199|    char *name = NULL;
  376|    199|    char *label = NULL;
  377|    199|    char *format = NULL;
  378|    199|    char *informat = NULL;
  379|       |
  380|    507|    for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (380:15): [True: 451, False: 56]
  ------------------
  381|    451|        int index, name_len, label_len, format_len, informat_len;
  382|    451|        if (read_bytes(ctx, labeldef, sizeof(labeldef)) != sizeof(labeldef)) {
  ------------------
  |  Branch (382:13): [True: 26, False: 425]
  ------------------
  383|     26|            retval = READSTAT_ERROR_READ;
  384|     26|            goto cleanup;
  385|     26|        }
  386|       |
  387|    425|        if (machine_is_little_endian()) {
  ------------------
  |  Branch (387:13): [True: 425, False: 0]
  ------------------
  388|    425|            index = byteswap2(labeldef[0]);
  389|    425|            name_len = byteswap2(labeldef[1]);
  390|    425|            label_len = byteswap2(labeldef[2]);
  391|    425|            format_len = byteswap2(labeldef[3]);
  392|    425|            informat_len = byteswap2(labeldef[4]);
  393|    425|        } else {
  394|      0|            index = labeldef[0];
  395|      0|            name_len = labeldef[1];
  396|      0|            label_len = labeldef[2];
  397|      0|            format_len = labeldef[3];
  398|      0|            informat_len = labeldef[4];
  399|      0|        }
  400|       |
  401|    425|        if (index > ctx->var_count || index == 0) {
  ------------------
  |  Branch (401:13): [True: 15, False: 410]
  |  Branch (401:39): [True: 10, False: 400]
  ------------------
  402|     25|            retval = READSTAT_ERROR_PARSE;
  403|     25|            goto cleanup;
  404|     25|        }
  405|       |
  406|    400|        name = realloc(name, name_len + 1);
  407|    400|        label = realloc(label, label_len + 1);
  408|    400|        format = realloc(format, format_len + 1);
  409|    400|        informat = realloc(informat, informat_len + 1);
  410|       |
  411|    400|        readstat_variable_t *variable = ctx->variables[index-1];
  412|       |
  413|    400|        if (read_bytes(ctx, name, name_len) != name_len ||
  ------------------
  |  Branch (413:13): [True: 19, False: 381]
  ------------------
  414|    381|                read_bytes(ctx, label, label_len) != label_len ||
  ------------------
  |  Branch (414:17): [True: 18, False: 363]
  ------------------
  415|    363|                read_bytes(ctx, format, format_len) != format_len ||
  ------------------
  |  Branch (415:17): [True: 17, False: 346]
  ------------------
  416|    346|                read_bytes(ctx, informat, informat_len) != informat_len) {
  ------------------
  |  Branch (416:17): [True: 19, False: 327]
  ------------------
  417|     73|            retval = READSTAT_ERROR_READ;
  418|     73|            goto cleanup;
  419|     73|        }
  420|       |
  421|    327|        retval = readstat_convert(variable->name, sizeof(variable->name),
  422|    327|                name, name_len, ctx->converter);
  423|    327|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (423:13): [True: 1, False: 326]
  ------------------
  424|      1|            goto cleanup;
  425|       |
  426|    326|        retval = readstat_convert(variable->label, sizeof(variable->label),
  427|    326|                label, label_len, ctx->converter);
  428|    326|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (428:13): [True: 2, False: 324]
  ------------------
  429|      2|            goto cleanup;
  430|       |
  431|    324|        retval = readstat_convert(variable->format, sizeof(variable->format),
  432|    324|                format, format_len, ctx->converter);
  433|    324|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (433:13): [True: 15, False: 309]
  ------------------
  434|     15|            goto cleanup;
  435|       |
  436|    309|        retval = readstat_convert(variable->informat, sizeof(variable->informat),
  437|    309|                informat, informat_len, ctx->converter);
  438|    309|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (438:13): [True: 1, False: 308]
  ------------------
  439|      1|            goto cleanup;
  440|    309|    }
  441|       |
  442|     56|    retval = xport_skip_rest_of_record(ctx);
  443|     56|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (443:9): [True: 24, False: 32]
  ------------------
  444|     24|        goto cleanup;
  445|       |
  446|     32|    retval = xport_read_obs_header_record(ctx);
  447|     32|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (447:9): [True: 31, False: 1]
  ------------------
  448|     31|        goto cleanup;
  449|       |
  450|    199|cleanup:
  451|    199|    free(name);
  452|    199|    free(format);
  453|    199|    free(informat);
  454|    199|    free(label);
  455|    199|    return retval;
  456|     32|}
readstat_xport_read.c:xport_read_data:
  629|    562|static readstat_error_t xport_read_data(xport_ctx_t *ctx) {
  630|    562|    if (!ctx->row_length)
  ------------------
  |  Branch (630:9): [True: 0, False: 562]
  ------------------
  631|      0|        return READSTAT_OK;
  632|       |
  633|    562|    if (!ctx->handle.value)
  ------------------
  |  Branch (633:9): [True: 0, False: 562]
  ------------------
  634|      0|        return READSTAT_OK;
  635|       |
  636|    562|    readstat_error_t retval = READSTAT_OK;
  637|    562|    char *row = readstat_malloc(ctx->row_length);
  638|    562|    char *blank_row = readstat_malloc(ctx->row_length);
  639|    562|    int num_blank_rows = 0;
  640|       |
  641|    562|    if (row == NULL || blank_row == NULL) {
  ------------------
  |  Branch (641:9): [True: 7, False: 555]
  |  Branch (641:24): [True: 0, False: 555]
  ------------------
  642|      7|        retval = READSTAT_ERROR_MALLOC;
  643|      7|        goto cleanup;
  644|      7|    }
  645|       |
  646|    555|    memset(blank_row, ' ', ctx->row_length);
  647|  43.3k|    while (1) {
  ------------------
  |  Branch (647:12): [True: 43.3k, Folded]
  ------------------
  648|  43.3k|        ssize_t bytes_read = read_bytes(ctx, row, ctx->row_length);
  649|  43.3k|        if (bytes_read == -1) {
  ------------------
  |  Branch (649:13): [True: 0, False: 43.3k]
  ------------------
  650|      0|            retval = READSTAT_ERROR_READ;
  651|      0|            goto cleanup;
  652|  43.3k|        } else if (bytes_read < ctx->row_length) {
  ------------------
  |  Branch (652:20): [True: 555, False: 42.8k]
  ------------------
  653|    555|            break;
  654|    555|        }
  655|       |
  656|  42.8k|        off_t pos = 0;
  657|       |
  658|  42.8k|        int row_is_blank = 1;
  659|       |
  660|  50.4k|        for (pos=0; pos<ctx->row_length; pos++) {
  ------------------
  |  Branch (660:21): [True: 48.7k, False: 1.64k]
  ------------------
  661|  48.7k|            if (row[pos] != ' ') {
  ------------------
  |  Branch (661:17): [True: 41.1k, False: 7.57k]
  ------------------
  662|  41.1k|                row_is_blank = 0;
  663|  41.1k|                break;
  664|  41.1k|            }
  665|  48.7k|        }
  666|       |
  667|  42.8k|        if (row_is_blank) {
  ------------------
  |  Branch (667:13): [True: 1.64k, False: 41.1k]
  ------------------
  668|  1.64k|            num_blank_rows++;
  669|  1.64k|            continue;
  670|  1.64k|        }
  671|       |
  672|  42.7k|        while (num_blank_rows) {
  ------------------
  |  Branch (672:16): [True: 1.57k, False: 41.1k]
  ------------------
  673|  1.57k|            retval = xport_process_row(ctx, blank_row, ctx->row_length);
  674|  1.57k|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (674:17): [True: 0, False: 1.57k]
  ------------------
  675|      0|                goto cleanup;
  676|       |
  677|  1.57k|            if (ctx->row_limit > 0 && ctx->parsed_row_count == ctx->row_limit)
  ------------------
  |  Branch (677:17): [True: 0, False: 1.57k]
  |  Branch (677:39): [True: 0, False: 0]
  ------------------
  678|      0|                goto cleanup;
  679|       |
  680|  1.57k|            num_blank_rows--;
  681|  1.57k|        }
  682|       |
  683|  41.1k|        retval = xport_process_row(ctx, row, ctx->row_length);
  684|  41.1k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (684:13): [True: 0, False: 41.1k]
  ------------------
  685|      0|            goto cleanup;
  686|       |
  687|  41.1k|        retval = xport_update_progress(ctx);
  688|  41.1k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (688:13): [True: 0, False: 41.1k]
  ------------------
  689|      0|            goto cleanup;
  690|       |
  691|  41.1k|        if (ctx->row_limit > 0 && ctx->parsed_row_count == ctx->row_limit)
  ------------------
  |  Branch (691:13): [True: 0, False: 41.1k]
  |  Branch (691:35): [True: 0, False: 0]
  ------------------
  692|      0|            break;
  693|  41.1k|    }
  694|       |
  695|    562|cleanup:
  696|    562|    if (row)
  ------------------
  |  Branch (696:9): [True: 555, False: 7]
  ------------------
  697|    555|        free(row);
  698|    562|    if (blank_row)
  ------------------
  |  Branch (698:9): [True: 555, False: 7]
  ------------------
  699|    555|        free(blank_row);
  700|    562|    return retval;
  701|    555|}
readstat_xport_read.c:xport_process_row:
  563|  42.7k|static readstat_error_t xport_process_row(xport_ctx_t *ctx, const char *row, size_t row_length) {
  564|  42.7k|    readstat_error_t retval = READSTAT_OK;
  565|  42.7k|    int i;
  566|  42.7k|    off_t pos = 0;
  567|  42.7k|    char *string = NULL;
  568|  85.8k|    for (i=0; i<ctx->var_count; i++) {
  ------------------
  |  Branch (568:15): [True: 43.1k, False: 42.7k]
  ------------------
  569|  43.1k|        readstat_variable_t *variable = ctx->variables[i];
  570|  43.1k|        readstat_value_t value = { .type = variable->type };
  571|       |
  572|  43.1k|        if (variable->type == READSTAT_TYPE_STRING) {
  ------------------
  |  Branch (572:13): [True: 1.11k, False: 42.0k]
  ------------------
  573|  1.11k|            string = readstat_realloc(string, 4*variable->storage_width+1);
  574|  1.11k|            if (string == NULL) {
  ------------------
  |  Branch (574:17): [True: 0, False: 1.11k]
  ------------------
  575|      0|                retval = READSTAT_ERROR_MALLOC;
  576|      0|                goto cleanup;
  577|      0|            }
  578|  1.11k|            retval = readstat_convert(string, 4*variable->storage_width+1,
  579|  1.11k|                    &row[pos], variable->storage_width, ctx->converter);
  580|  1.11k|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (580:17): [True: 0, False: 1.11k]
  ------------------
  581|      0|                goto cleanup;
  582|       |
  583|  1.11k|            value.v.string_value = string;
  584|  42.0k|        } else {
  585|  42.0k|            double dval = NAN;
  586|  42.0k|            if (variable->storage_width <= XPORT_MAX_DOUBLE_SIZE &&
  ------------------
  |  |   45|  84.0k|#define XPORT_MAX_DOUBLE_SIZE   8
  ------------------
  |  Branch (586:17): [True: 41.7k, False: 232]
  ------------------
  587|  41.7k|                    variable->storage_width >= XPORT_MIN_DOUBLE_SIZE) {
  ------------------
  |  |   44|  41.7k|#define XPORT_MIN_DOUBLE_SIZE   3
  ------------------
  |  Branch (587:21): [True: 40.2k, False: 1.55k]
  ------------------
  588|  40.2k|                char full_value[8] = { 0 };
  589|  40.2k|                if (memcmp(&full_value[1], &row[pos+1], variable->storage_width - 1) == 0 &&
  ------------------
  |  Branch (589:21): [True: 34.4k, False: 5.73k]
  ------------------
  590|  34.4k|                        (row[pos] == '.' || sas_validate_tag(row[pos]) == READSTAT_OK)) {
  ------------------
  |  Branch (590:26): [True: 194, False: 34.3k]
  |  Branch (590:45): [True: 397, False: 33.9k]
  ------------------
  591|    591|                    if (row[pos] == '.') {
  ------------------
  |  Branch (591:25): [True: 194, False: 397]
  ------------------
  592|    194|                        value.is_system_missing = 1;
  593|    397|                    } else {
  594|    397|                        value.tag = row[pos];
  595|    397|                        value.is_tagged_missing = 1;
  596|    397|                    }
  597|  39.6k|                } else {
  598|  39.6k|                    memcpy(full_value, &row[pos], variable->storage_width);
  599|  39.6k|                    int rc = cnxptiee(full_value, CN_TYPE_XPORT, &dval, CN_TYPE_NATIVE);
  ------------------
  |  |    2|  39.6k|#define CN_TYPE_XPORT 1
  ------------------
                                  int rc = cnxptiee(full_value, CN_TYPE_XPORT, &dval, CN_TYPE_NATIVE);
  ------------------
  |  |    1|  39.6k|#define CN_TYPE_NATIVE 0
  ------------------
  600|  39.6k|                    if (rc != 0) {
  ------------------
  |  Branch (600:25): [True: 0, False: 39.6k]
  ------------------
  601|      0|                        retval = READSTAT_ERROR_CONVERT;
  602|      0|                        goto cleanup;
  603|      0|                    }
  604|  39.6k|                }
  605|  40.2k|            }
  606|       |
  607|  42.0k|            value.v.double_value = dval;
  608|  42.0k|        }
  609|  43.1k|        pos += variable->storage_width;
  610|       |
  611|  43.1k|        if (ctx->handle.value && !ctx->variables[i]->skip && !ctx->row_offset) {
  ------------------
  |  Branch (611:13): [True: 43.1k, False: 0]
  |  Branch (611:34): [True: 43.1k, False: 0]
  |  Branch (611:62): [True: 43.1k, False: 0]
  ------------------
  612|  43.1k|            if (ctx->handle.value(ctx->parsed_row_count, variable, value, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (612:17): [True: 0, False: 43.1k]
  ------------------
  613|      0|                retval = READSTAT_ERROR_USER_ABORT;
  614|      0|                goto cleanup;
  615|      0|            }
  616|  43.1k|        }
  617|  43.1k|    }
  618|  42.7k|    if (ctx->row_offset) {
  ------------------
  |  Branch (618:9): [True: 0, False: 42.7k]
  ------------------
  619|      0|        ctx->row_offset--;
  620|  42.7k|    } else {
  621|  42.7k|        ctx->parsed_row_count++;
  622|  42.7k|    }
  623|       |
  624|  42.7k|cleanup:
  625|  42.7k|    free(string);
  626|  42.7k|    return retval;
  627|  42.7k|}
readstat_xport_read.c:xport_update_progress:
   43|  41.1k|static readstat_error_t xport_update_progress(xport_ctx_t *ctx) {
   44|  41.1k|    readstat_io_t *io = ctx->io;
   45|  41.1k|    return io->update(ctx->file_size, ctx->handle.progress, ctx->user_ctx, io->io_ctx);
   46|  41.1k|}
readstat_xport_read.c:xport_ctx_free:
   53|  1.53k|static void xport_ctx_free(xport_ctx_t *ctx) {
   54|  1.53k|    if (ctx->variables) {
  ------------------
  |  Branch (54:9): [True: 1.04k, False: 483]
  ------------------
   55|  1.04k|        int i;
   56|  1.04M|        for (i=0; i<ctx->var_count; i++) {
  ------------------
  |  Branch (56:19): [True: 1.04M, False: 1.04k]
  ------------------
   57|  1.04M|            if (ctx->variables[i])
  ------------------
  |  Branch (57:17): [True: 96.7k, False: 947k]
  ------------------
   58|  96.7k|                free(ctx->variables[i]);
   59|  1.04M|        }
   60|  1.04k|        free(ctx->variables);
   61|  1.04k|    }
   62|  1.53k|    if (ctx->converter) {
  ------------------
  |  Branch (62:9): [True: 0, False: 1.53k]
  ------------------
   63|      0|        iconv_close(ctx->converter);
   64|      0|    }
   65|       |
   66|  1.53k|    free(ctx);
   67|  1.53k|}

rt_open_handler:
    8|  1.53k|int rt_open_handler(const char *path, void *io_ctx) {
    9|  1.53k|    return 0;
   10|  1.53k|}
rt_close_handler:
   12|  1.53k|int rt_close_handler(void *io_ctx) {
   13|  1.53k|    return 0;
   14|  1.53k|}
rt_seek_handler:
   17|  6.59k|        readstat_io_flags_t whence, void *io_ctx) {
   18|  6.59k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   19|  6.59k|    readstat_off_t newpos = -1;
   20|  6.59k|    if (whence == READSTAT_SEEK_SET) {
  ------------------
  |  Branch (20:9): [True: 1.53k, False: 5.06k]
  ------------------
   21|  1.53k|        newpos = offset;
   22|  5.06k|    } else if (whence == READSTAT_SEEK_CUR) {
  ------------------
  |  Branch (22:16): [True: 3.53k, False: 1.53k]
  ------------------
   23|  3.53k|        newpos = buffer_ctx->pos + offset;
   24|  3.53k|    } else if (whence == READSTAT_SEEK_END) {
  ------------------
  |  Branch (24:16): [True: 1.53k, False: 0]
  ------------------
   25|  1.53k|        newpos = buffer_ctx->buffer->used + offset;
   26|  1.53k|    }
   27|       |
   28|  6.59k|    if (newpos < 0)
  ------------------
  |  Branch (28:9): [True: 0, False: 6.59k]
  ------------------
   29|      0|        return -1;
   30|       |
   31|  6.59k|    if (newpos > buffer_ctx->buffer->used)
  ------------------
  |  Branch (31:9): [True: 80, False: 6.51k]
  ------------------
   32|     80|        return -1;
   33|       |
   34|  6.51k|    buffer_ctx->pos = newpos;
   35|  6.51k|    return newpos;
   36|  6.59k|}
rt_read_handler:
   38|   154k|ssize_t rt_read_handler(void *buf, size_t nbytes, void *io_ctx) {
   39|   154k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   40|   154k|    ssize_t bytes_copied = 0;
   41|   154k|    ssize_t bytes_left = buffer_ctx->buffer->used - buffer_ctx->pos;
   42|   154k|    if (nbytes <= bytes_left) {
  ------------------
  |  Branch (42:9): [True: 153k, False: 1.00k]
  ------------------
   43|   153k|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, nbytes);
   44|   153k|        bytes_copied = nbytes;
   45|   153k|    } else if (bytes_left > 0) {
  ------------------
  |  Branch (45:16): [True: 165, False: 840]
  ------------------
   46|    165|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, bytes_left);
   47|    165|        bytes_copied = bytes_left;
   48|    165|    }
   49|   154k|    buffer_ctx->pos += bytes_copied;
   50|   154k|    return bytes_copied;
   51|   154k|}
rt_update_handler:
   54|  41.1k|        void *user_ctx, void *io_ctx) {
   55|  41.1k|    if (!progress_handler)
  ------------------
  |  Branch (55:9): [True: 41.1k, False: 0]
  ------------------
   56|  41.1k|        return READSTAT_OK;
   57|       |
   58|      0|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   59|       |
   60|      0|    if (progress_handler(1.0 * buffer_ctx->pos / buffer_ctx->buffer->used, user_ctx))
  ------------------
  |  Branch (60:9): [True: 0, False: 0]
  ------------------
   61|      0|        return READSTAT_ERROR_USER_ABORT;
   62|       |
   63|      0|    return READSTAT_OK;
   64|      0|}

