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

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

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

readstat_convert:
    7|   371k|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|  5.75M|    while (src_len && (src[src_len-1] == ' ' || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (10:12): [True: 5.53M, False: 212k]
  |  Branch (10:24): [True: 2.65M, False: 2.88M]
  |  Branch (10:49): [True: 2.72M, False: 158k]
  ------------------
   11|  5.38M|        src_len--;
   12|  5.38M|    }
   13|   371k|    if (dst_len == 0) {
  ------------------
  |  Branch (13:9): [True: 0, False: 371k]
  ------------------
   14|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   15|   371k|    } else if (converter) {
  ------------------
  |  Branch (15:16): [True: 0, False: 371k]
  ------------------
   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|   371k|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (29:16): [True: 24, False: 371k]
  ------------------
   30|     24|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   31|   371k|    } else {
   32|   371k|        memcpy(dst, src, src_len);
   33|   371k|        dst[src_len] = '\0';
   34|   371k|    }
   35|   371k|    return READSTAT_OK;
   36|   371k|}

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

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

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

memreverse:
   22|  92.1k|void memreverse(void *intp_void, int l) {
   23|  92.1k|    if (!machine_is_little_endian())
  ------------------
  |  Branch (23:9): [True: 0, False: 92.1k]
  ------------------
   24|      0|        return;
   25|       |
   26|  92.1k|    int i,j;
   27|  92.1k|    char save;
   28|  92.1k|    char *intp = (char *)intp_void;
   29|       |
   30|  92.1k|    j = l/2;
   31|   276k|    for (i=0;i<j;i++) {
  ------------------
  |  Branch (31:14): [True: 184k, False: 92.1k]
  ------------------
   32|   184k|        save = intp[i];
   33|   184k|        intp[i] = intp[l-i-1];
   34|   184k|        intp[l-i-1] = save;
   35|   184k|    }
   36|  92.1k|}
cnxptiee:
   39|  40.1k|{
   40|  40.1k|    unsigned char *from = (unsigned char *)from_bytes;
   41|  40.1k|    unsigned char *to = (unsigned char *)to_bytes;
   42|  40.1k|    unsigned char temp[8];
   43|  40.1k|    int i;
   44|       |
   45|  40.1k|    if (fromtype == CN_TYPE_NATIVE) {
  ------------------
  |  |    1|  40.1k|#define CN_TYPE_NATIVE 0
  ------------------
  |  Branch (45:9): [True: 0, False: 40.1k]
  ------------------
   46|      0|        fromtype = FLOATREP;
  ------------------
  |  |   18|      0|#define FLOATREP get_native()
  ------------------
   47|      0|    }
   48|  40.1k|    switch(fromtype) {
   49|      0|        case CN_TYPE_IEEEL :
  ------------------
  |  |    4|      0|#define CN_TYPE_IEEEL 3
  ------------------
  |  Branch (49:9): [True: 0, False: 40.1k]
  ------------------
   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: 40.1k]
  ------------------
   59|       |            /* Break intentionally omitted. */
   60|  40.1k|        case CN_TYPE_XPORT :
  ------------------
  |  |    2|  40.1k|#define CN_TYPE_XPORT 1
  ------------------
  |  Branch (60:9): [True: 40.1k, False: 0]
  ------------------
   61|  40.1k|            break;
   62|      0|        default:
  ------------------
  |  Branch (62:9): [True: 0, False: 40.1k]
  ------------------
   63|      0|            return(-1);
   64|  40.1k|    }
   65|  40.1k|    if (totype == CN_TYPE_NATIVE) {
  ------------------
  |  |    1|  40.1k|#define CN_TYPE_NATIVE 0
  ------------------
  |  Branch (65:9): [True: 40.1k, False: 0]
  ------------------
   66|  40.1k|        totype = FLOATREP;
  ------------------
  |  |   18|  40.1k|#define FLOATREP get_native()
  ------------------
   67|  40.1k|    }
   68|  40.1k|    switch(totype) {
   69|      0|        case CN_TYPE_XPORT :
  ------------------
  |  |    2|      0|#define CN_TYPE_XPORT 1
  ------------------
  |  Branch (69:9): [True: 0, False: 40.1k]
  ------------------
   70|      0|        case CN_TYPE_IEEEB :
  ------------------
  |  |    3|      0|#define CN_TYPE_IEEEB 2
  ------------------
  |  Branch (70:9): [True: 0, False: 40.1k]
  ------------------
   71|  40.1k|        case CN_TYPE_IEEEL :
  ------------------
  |  |    4|  40.1k|#define CN_TYPE_IEEEL 3
  ------------------
  |  Branch (71:9): [True: 40.1k, False: 0]
  ------------------
   72|  40.1k|            break;
   73|      0|        default:
  ------------------
  |  Branch (73:9): [True: 0, False: 40.1k]
  ------------------
   74|      0|            return(-2);
   75|  40.1k|    }
   76|  40.1k|    if (fromtype == totype) {
  ------------------
  |  Branch (76:9): [True: 0, False: 40.1k]
  ------------------
   77|      0|        memcpy(to,from,8);
   78|      0|        return(0);
   79|      0|    }
   80|  40.1k|    switch(fromtype) {
  ------------------
  |  Branch (80:12): [True: 40.1k, False: 0]
  ------------------
   81|      0|        case CN_TYPE_IEEEB :
  ------------------
  |  |    3|      0|#define CN_TYPE_IEEEB 2
  ------------------
  |  Branch (81:9): [True: 0, False: 40.1k]
  ------------------
   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|  40.1k|        case CN_TYPE_XPORT :
  ------------------
  |  |    2|  40.1k|#define CN_TYPE_XPORT 1
  ------------------
  |  Branch (86:9): [True: 40.1k, False: 0]
  ------------------
   87|  40.1k|            xpt2ieee(from,to);
   88|  40.1k|            break;
   89|  40.1k|    }
   90|  40.1k|    if (totype == CN_TYPE_IEEEL) {
  ------------------
  |  |    4|  40.1k|#define CN_TYPE_IEEEL 3
  ------------------
  |  Branch (90:9): [True: 40.1k, False: 0]
  ------------------
   91|  40.1k|        memcpy(temp,to,8);
   92|   360k|        for (i=7;i>=0;i--) {
  ------------------
  |  Branch (92:18): [True: 320k, False: 40.1k]
  ------------------
   93|   320k|            to[7-i] = temp[i];
   94|   320k|        }
   95|  40.1k|    }
   96|  40.1k|    return(0);
   97|  40.1k|}
get_native:
   99|  40.1k|int get_native(void) {
  100|  40.1k|    static unsigned char float_reps[][8] = {
  101|  40.1k|        {0x41,0x10,0x00,0x00,0x00,0x00,0x00,0x00},
  102|  40.1k|        {0x3f,0xf0,0x00,0x00,0x00,0x00,0x00,0x00},
  103|  40.1k|        {0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f}
  104|  40.1k|    };
  105|       |
  106|  40.1k|    static double one = 1.00;
  107|       |
  108|  40.1k|    int i,j;
  109|  40.1k|    j = sizeof(float_reps)/8;
  110|   120k|    for (i=0;i<j;i++)  {
  ------------------
  |  Branch (110:14): [True: 120k, False: 0]
  ------------------
  111|   120k|        if (memcmp(&one,float_reps+i,8) == 0)
  ------------------
  |  Branch (111:13): [True: 40.1k, False: 80.2k]
  ------------------
  112|  40.1k|            return(i+1);
  113|   120k|    }
  114|      0|    return(-1);
  115|  40.1k|}
ieee.c:xpt2ieee:
  117|  40.1k|void xpt2ieee(unsigned char *xport, unsigned char *ieee) {
  118|  40.1k|    char temp[8];
  119|  40.1k|    register int shift;
  120|  40.1k|    register int nib;
  121|  40.1k|    uint32_t ieee1,ieee2;
  122|  40.1k|    uint32_t xport1 = 0;
  123|  40.1k|    uint32_t xport2 = 0;
  124|       |
  125|  40.1k|    memcpy(temp,xport,8);
  126|  40.1k|    memset(ieee,0,8);
  127|       |
  128|  40.1k|    if (*temp && memcmp(temp+1,ieee,7) == 0) {
  ------------------
  |  Branch (128:9): [True: 6.21k, False: 33.8k]
  |  Branch (128:18): [True: 241, False: 5.97k]
  ------------------
  129|    241|        ieee[0] = ieee[1] = 0xff;
  130|    241|        ieee[2] = ~(*temp);
  131|    241|        return;
  132|    241|    }
  133|       |
  134|  39.8k|    memcpy(&xport1,temp,sizeof(uint32_t));
  135|  39.8k|    memreverse(&xport1,sizeof(uint32_t));
  136|  39.8k|    memcpy(&xport2,temp+4,sizeof(uint32_t));
  137|  39.8k|    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.8k|    if ((xport1 & 0x7fffffff) == 0x7fffffff && xport2 == 0xffffffff) {
  ------------------
  |  Branch (184:9): [True: 627, False: 39.2k]
  |  Branch (184:48): [True: 194, False: 433]
  ------------------
  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.6k|    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.6k|    if ((!(ieee2 = xport2)) && !xport1)
  ------------------
  |  Branch (197:9): [True: 35.1k, False: 4.53k]
  |  Branch (197:32): [True: 33.6k, False: 1.48k]
  ------------------
  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|  6.01k|    if ((nib = (int)xport1) & 0x00800000) {
  ------------------
  |  Branch (206:9): [True: 2.94k, False: 3.07k]
  ------------------
  207|  2.94k|        shift = 3;
  208|  3.07k|    } else if (nib & 0x00400000) {
  ------------------
  |  Branch (208:16): [True: 779, False: 2.29k]
  ------------------
  209|    779|        shift = 2;
  210|  2.29k|    } else if (nib & 0x00200000) {
  ------------------
  |  Branch (210:16): [True: 1.79k, False: 499]
  ------------------
  211|  1.79k|        shift = 1;
  212|  1.79k|    } else {
  213|    499|        shift = 0;
  214|    499|    }
  215|       |
  216|  6.01k|    if (shift) {
  ------------------
  |  Branch (216:9): [True: 5.51k, False: 499]
  ------------------
  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.51k|        ieee1 >>= shift;
  225|  5.51k|        ieee2 = (xport2 >> shift) |
  226|  5.51k|            ((xport1 & 0x00000007) << (29 + (3 - shift)));
  227|  5.51k|    }
  228|       |
  229|       |    /* clear the 1 bit to the left of the binary point */
  230|  6.01k|    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|  6.01k|    ieee1 |=
  239|  6.01k|        (((((int32_t)(*temp & 0x7f) - 65) * 4) + shift + 1023) << 20) |
  240|  6.01k|        (xport1 & 0x80000000);
  241|       |
  242|  6.21k|doret:
  243|  6.21k|    memreverse(&ieee1,sizeof(uint32_t));
  244|  6.21k|    memcpy(ieee,&ieee1,sizeof(uint32_t));
  245|  6.21k|    memreverse(&ieee2,sizeof(uint32_t));
  246|  6.21k|    memcpy(ieee+4,&ieee2,sizeof(uint32_t));
  247|  6.21k|    return;
  248|  6.01k|}

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: 209, False: 34.0k]
  |  Branch (508:24): [True: 418, False: 33.6k]
  |  Branch (508:38): [True: 203, False: 215]
  ------------------
  509|    412|        return READSTAT_OK;
  510|       |
  511|  33.8k|    return READSTAT_ERROR_TAGGED_VALUE_IS_OUT_OF_RANGE;
  512|  34.3k|}

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

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

rt_open_handler:
    8|  1.55k|int rt_open_handler(const char *path, void *io_ctx) {
    9|  1.55k|    return 0;
   10|  1.55k|}
rt_close_handler:
   12|  1.55k|int rt_close_handler(void *io_ctx) {
   13|  1.55k|    return 0;
   14|  1.55k|}
rt_seek_handler:
   17|  6.69k|        readstat_io_flags_t whence, void *io_ctx) {
   18|  6.69k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   19|  6.69k|    readstat_off_t newpos = -1;
   20|  6.69k|    if (whence == READSTAT_SEEK_SET) {
  ------------------
  |  Branch (20:9): [True: 1.55k, False: 5.14k]
  ------------------
   21|  1.55k|        newpos = offset;
   22|  5.14k|    } else if (whence == READSTAT_SEEK_CUR) {
  ------------------
  |  Branch (22:16): [True: 3.58k, False: 1.55k]
  ------------------
   23|  3.58k|        newpos = buffer_ctx->pos + offset;
   24|  3.58k|    } else if (whence == READSTAT_SEEK_END) {
  ------------------
  |  Branch (24:16): [True: 1.55k, False: 0]
  ------------------
   25|  1.55k|        newpos = buffer_ctx->buffer->used + offset;
   26|  1.55k|    }
   27|       |
   28|  6.69k|    if (newpos < 0)
  ------------------
  |  Branch (28:9): [True: 0, False: 6.69k]
  ------------------
   29|      0|        return -1;
   30|       |
   31|  6.69k|    if (newpos > buffer_ctx->buffer->used)
  ------------------
  |  Branch (31:9): [True: 80, False: 6.61k]
  ------------------
   32|     80|        return -1;
   33|       |
   34|  6.61k|    buffer_ctx->pos = newpos;
   35|  6.61k|    return newpos;
   36|  6.69k|}
rt_read_handler:
   38|   149k|ssize_t rt_read_handler(void *buf, size_t nbytes, void *io_ctx) {
   39|   149k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   40|   149k|    ssize_t bytes_copied = 0;
   41|   149k|    ssize_t bytes_left = buffer_ctx->buffer->used - buffer_ctx->pos;
   42|   149k|    if (nbytes <= bytes_left) {
  ------------------
  |  Branch (42:9): [True: 148k, False: 1.01k]
  ------------------
   43|   148k|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, nbytes);
   44|   148k|        bytes_copied = nbytes;
   45|   148k|    } else if (bytes_left > 0) {
  ------------------
  |  Branch (45:16): [True: 169, False: 850]
  ------------------
   46|    169|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, bytes_left);
   47|    169|        bytes_copied = bytes_left;
   48|    169|    }
   49|   149k|    buffer_ctx->pos += bytes_copied;
   50|   149k|    return bytes_copied;
   51|   149k|}
rt_update_handler:
   54|  41.7k|        void *user_ctx, void *io_ctx) {
   55|  41.7k|    if (!progress_handler)
  ------------------
  |  Branch (55:9): [True: 41.7k, False: 0]
  ------------------
   56|  41.7k|        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|}

