Re: [Quickfix-developers] Field with embedded null character
Brought to you by:
orenmnero
From: Caleb E. <cal...@gm...> - 2004-10-28 16:02:12
|
On Thu, 28 Oct 2004 09:05:47 -0400, Caleb Epstein <cal...@gm...> wrote: > That said, it does seem that QuickFIX has a bug in the message > serialization code when dealing with fields having embedded \0 bytes: Ironically, the bug turns out to be in code that I submitted. In Field.h there is this optimization: char buf[64]; if( 13 + m_string.length() < sizeof(buf) ) { m_length = sprintf( buf, "%d=%*.*s\001", m_field, (int)m_string.length(), (int)m_string.length(), m_string.data() ); m_data.assign( buf, m_length ); } At least on Linux, sprintf refuses to write anything after a \0 byte to the output buffer, so the field gets padded with spaces on the left. Here's a re-worked version that is not as simple but is still faster than the string + string + ... implementation that is used when the value is too long to fit in buf: char buf[64]; if( 13 + m_string.length() < sizeof(buf) ) { int fidlen = sprintf (buf, "%d=", m_field); m_length = fidlen + m_string.length() + 1; memcpy (buf + fidlen, m_string.data(), m_string.length()); buf[m_length - 1] = '\001'; m_data.assign (buf, m_length); } -- Caleb Epstein cal...@gm... |