<commit_before>#include <iostream>
#include <queue>
#include <sys/time.h>
#include <cassert>

#include "zcm/zcm-cpp.hpp"

#include "zcm/transport/generic_serial_transport.h"
#include "types/example_t.hpp"

using namespace std;
using namespace zcm;

#define PUBLISH_DT (1e6)/(5)
#define BUFFER_SIZE 200
#define MIN(A, B) ((A) < (B)) ? (A) : (B)

#define MAX_FIFO 12

queue<uint8_t> fifo;

static uint32_t get(uint8_t* data, uint32_t nData, void* usr)
{
    unsigned n = MIN(MAX_FIFO, nData);
    n = MIN(fifo.size(), n);

    unsigned i;

    for (i = 0; i < n; i++) {
        data[i] = fifo.front();
        fifo.pop();
    }

    return n;
}

static uint32_t put(const uint8_t* data, uint32_t nData, void* usr)
{
    unsigned n = MIN(MAX_FIFO - fifo.size(), nData);
    //cout << "Put " << n << " bytes" << endl;

    unsigned i;
    for (i = 0; i < n; i++)
        fifo.push(data[i]);

    return n;
}

static uint64_t utime(void* usr)
{
    struct timeval tv;
    gettimeofday(&tv, NULL);
    return (uint64_t)tv.tv_sec * 1000000 + tv.tv_usec;
}

class Handler
{
    int64_t lastHost = 0;

  public:
    void handle(const ReceiveBuffer* rbuf, const string& chan, const example_t* msg)
    {
        cout << "Message received" << endl;

        if (msg->timestamp <= lastHost || rbuf->recv_utime < lastHost)  {
            assert("ERROR: utime mismatch. This should never happen");
        }
        lastHost = msg->timestamp;

    }
};

int main(int argc, const char *argv[])
{
    ZCM zcmLocal(zcm_trans_generic_serial_create(&get, &put, NULL, &utime, NULL));

    example_t example;
    example.num_ranges = 1;
    example.ranges.resize(1);
    example.ranges.at(0) = 1;

    Handler handler;
    auto sub = zcmLocal.subscribe("EXAMPLE", &Handler::handle, &handler);
<commit_msg>fixed conditional jump based on uninitialized variable warning in valgrind<commit_after>#include <iostream>
#include <queue>
#include <sys/time.h>
#include <cassert>

#include "zcm/zcm-cpp.hpp"

#include "zcm/transport/generic_serial_transport.h"
#include "types/example_t.hpp"

using namespace std;
using namespace zcm;

#define PUBLISH_DT (1e6)/(5)
#define BUFFER_SIZE 200
#define MIN(A, B) ((A) < (B)) ? (A) : (B)

#define MAX_FIFO 12

queue<uint8_t> fifo;

static uint32_t get(uint8_t* data, uint32_t nData, void* usr)
{
    unsigned n = MIN(MAX_FIFO, nData);
    n = MIN(fifo.size(), n);

    unsigned i;

    for (i = 0; i < n; i++) {
        data[i] = fifo.front();
        fifo.pop();
    }

    return n;
}

static uint32_t put(const uint8_t* data, uint32_t nData, void* usr)
{
    unsigned n = MIN(MAX_FIFO - fifo.size(), nData);
    //cout << "Put " << n << " bytes" << endl;

    unsigned i;
    for (i = 0; i < n; i++)
        fifo.push(data[i]);

    return n;
}

static uint64_t utime(void* usr)
{
    struct timeval tv;
    gettimeofday(&tv, NULL);
    return (uint64_t)tv.tv_sec * 1000000 + tv.tv_usec;
}

class Handler
{
    int64_t lastHost = 0;

  public:
    void handle(const ReceiveBuffer* rbuf, const string& chan, const example_t* msg)
    {
        cout << "Message received" << endl;

        if (msg->timestamp <= lastHost || rbuf->recv_utime < lastHost)  {
            assert("ERROR: utime mismatch. This should never happen");
        }
        lastHost = msg->timestamp;

    }
};

int main(int argc, const char *argv[])
{
    ZCM zcmLocal(zcm_trans_generic_serial_create(&get, &put, NULL, &utime, NULL));

    example_t example = {};
    example.num_ranges = 1;
    example.ranges.resize(1);
    example.ranges.at(0) = 1;

    Handler handler;
    auto sub = zcmLocal.subscribe("EXAMPLE", &Handler::handle, &handler);

{'fraction_non_alphanumeric': 0.14832140891579526, 'fraction_numerical': 0.02146395156851954, 'mean_word_length': 3.1027088036117383, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '666565', 'n_tokens_mistral': 1437, 'n_tokens_neox': 1352, 'n_words': 347}