<commit_before>/**
 * Copyright (c) 2015 Runtime Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include "bootutil/image.h"
#include "crc32.h"

#if !defined(__BYTE_ORDER__) || (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
#error "Machine must be little endian"
#endif

static void
print_usage(FILE *stream)
{
    fprintf(stream, "usage: bin2img <in-filename> <out-filename> <version>\n");
    fprintf(stream, "\n");
    fprintf(stream, "version numbers are of the form: XX.XX.XXXX.XXXXXXXX\n");
}

static int
parse_ver(struct image_version *out_ver, char *s)
{
    unsigned long ul;
    char *tok;
    char *ep;

    tok = strtok(s, ".");
    if (tok == NULL) {
        return -1;
    }

    ul = strtoul(tok, &ep, 16);
    if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT8_MAX) {
        return -1;
    }
    out_ver->iv_major = ul;

    tok = strtok(NULL, ".");
    if (tok == NULL) {
        return -1;
    }

    ul = strtoul(tok, &ep, 16);
    if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT8_MAX) {
        return -1;
    }
    out_ver->iv_minor = ul;

    tok = strtok(NULL, ".");
    if (tok == NULL) {
        return -1;
    }

    ul = strtoul(tok, &ep, 16);
    if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT16_MAX) {
        return -1;
    }
    out_ver->iv_revision = ul;

    ul = strtoul(tok, &ep, 16);
    if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT32_MAX) {
        return -1;
    }
    out_ver->iv_build_num = ul;

    return 0;<commit_msg>build number was not parsed from right token.<commit_after>/**
 * Copyright (c) 2015 Runtime Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include "bootutil/image.h"
#include "crc32.h"

#if !defined(__BYTE_ORDER__) || (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
#error "Machine must be little endian"
#endif

static void
print_usage(FILE *stream)
{
    fprintf(stream, "usage: bin2img <in-filename> <out-filename> <version>\n");
    fprintf(stream, "\n");
    fprintf(stream, "version numbers are of the form: XX.XX.XXXX.XXXXXXXX\n");
}

static int
parse_ver(struct image_version *out_ver, char *s)
{
    unsigned long ul;
    char *tok;
    char *ep;

    tok = strtok(s, ".");
    if (tok == NULL) {
        return -1;
    }

    ul = strtoul(tok, &ep, 16);
    if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT8_MAX) {
        return -1;
    }
    out_ver->iv_major = ul;

    tok = strtok(NULL, ".");
    if (tok == NULL) {
        return -1;
    }

    ul = strtoul(tok, &ep, 16);
    if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT8_MAX) {
        return -1;
    }
    out_ver->iv_minor = ul;

    tok = strtok(NULL, ".");
    if (tok == NULL) {
        return -1;
    }

    ul = strtoul(tok, &ep, 16);
    if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT16_MAX) {
        return -1;
    }
    out_ver->iv_revision = ul;

    tok = strtok(NULL, ".");
    if (tok == NULL) {
        return -1;
    }
    ul = strtoul(tok, &ep, 16);
    if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT32_MAX) {
        return -1;
    }
    out_ver->iv_build_num = ul;

    return 0;
{'fraction_non_alphanumeric': 0.1615720524017467, 'fraction_numerical': 0.022753390025281546, 'mean_word_length': 2.6912637828668364, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6693057', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1547, 'n_words': 473}