Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCC Linux Simple Example Using DataFile Core Dumps #9

Open
richjohnson905-home opened this issue Mar 4, 2022 · 0 comments
Open

GCC Linux Simple Example Using DataFile Core Dumps #9

richjohnson905-home opened this issue Mar 4, 2022 · 0 comments

Comments

@richjohnson905-home
Copy link

richjohnson905-home commented Mar 4, 2022

Following the example for DataFile.cc (bottom of page) at: https://avro.apache.org/docs/current/api/cpp/html/index.html

The example runs fine on macos but on any gcc linux system (ubuntu 18.04, debian buster, etc) the program core dumps for uninitialized value. The target is linux.

I use conan to pull in the lib:

[requires]
  libavrocpp/1.10.2

[generators]
  cmake

I could really use some help on this. I don't see any other c++ solutions and the client is in need.

dbh-vm :: CLionProjects/AvroLastChance/cmake-build-debug » valgrind ./bin/AvroLastChance                                                               
139 ↵
==42562== Memcheck, a memory error detector
==42562== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==42562== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==42562== Command: ./bin/AvroLastChance
==42562== 
==42562== Use of uninitialised value of size 8
==42562==    at 0x11B0B2: avro::codec_traits<double>::encode(avro::Encoder&, double) (Specific.hh:151)
==42562==    by 0x11B214: void avro::encode<double>(avro::Encoder&, double const&) (Specific.hh:332)
==42562==    by 0x11B11C: avro::codec_traits<c::cpx>::encode(avro::Encoder&, c::cpx const&) (cpx.hh:44)
==42562==    by 0x11B51C: void avro::encode<c::cpx>(avro::Encoder&, c::cpx const&) (Specific.hh:332)
==42562==    by 0x11B37B: avro::DataFileWriter<c::cpx>::write(c::cpx const&) (DataFile.hh:166)
==42562==    by 0x11AF7E: test2() (main.cpp:52)
==42562==    by 0x11AEE0: main (main.cpp:39)

Schema (generated the cpx.hh with avrogencpp tool): avrogencpp -i cpx.json -o cpx.hh -n c

{
  "type": "record",
  "name": "cpx",
  "fields" : [
    {
      "name": "re",
      "type": "double"
    },
    {
      "name": "im",
      "type" : "double"
    }
  ]
}

Code:

 #include <iostream>
#include "cpx.hh"
#include "avro/Encoder.hh"
#include "avro/Decoder.hh"
#include "avro/ValidSchema.hh"
#include "avro/Compiler.hh"
#include "avro/DataFile.hh"
#include <fstream>

avro::ValidSchema loadSchema(const char* filename)
{
   std::ifstream ifs(filename);
   avro::ValidSchema result;
   avro::compileJsonSchema(ifs, result);
   return result;
}

int main()
{
   avro::ValidSchema cpxSchema = loadSchema("cpx.json");
   {
      avro::DataFileWriter<c::cpx> dfw("test.avro", cpxSchema);
      c::cpx c1;
      for (int i = 0; i < 100; i++) {
         c1.re = i * 100;
         c1.im = i + 100;
         dfw.write(c1);
      }
      dfw.close();
   }
   return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant