Skip to content

Commit

Permalink
Follow up to 3994 and Fix sprintf Warnings
Browse files Browse the repository at this point in the history
OpenDDS#3994

- Fixed missing `TAO_VERSION_CODE` on TAO 2.2 by using
  `TAO_MAJOR_VERSION` instead.
- Replaced reference to bugzilla ticket with
  DOCGroup/ACE_TAO#2037
- Cleaned up and added sorting option for `update_gitignore.pl` used in
  OpenDDS#3994
- Replaced sprintf usage to satisfy build_m12_i0_j_FM-1f GHA warnings
  • Loading branch information
iguessthislldo committed Jan 25, 2023
1 parent 96ca54c commit 644a52f
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 65 deletions.
2 changes: 1 addition & 1 deletion dds/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/CharSeqS.h
/CharSeqS.inl
/DdsDcps.mpc.orig
/DdsDcps_lem_stub_export.h
/DdsDcpsC.cpp
/DdsDcpsC.h
/DdsDcpsC.inl
Expand Down Expand Up @@ -196,7 +197,6 @@
/DdsDcpsTypeSupportExtS.cpp
/DdsDcpsTypeSupportExtS.h
/DdsDcpsTypeSupportExtS.inl
/DdsDcps_lem_stub_export.h
/DdsDynamicDataC.cpp
/DdsDynamicDataC.h
/DdsDynamicDataC.inl
Expand Down
2 changes: 1 addition & 1 deletion dds/CORBA/tao/Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ CORBA::Exception::Exception (const CORBA::Exception &src)
// responsible for releasing any storage owned by the exception. It
// can do this because it's got the local name and the id.

#if TAO_VERSION_CODE < TAO_MAKE_VERSION_CODE(3,0,1)
#if TAO_MAJOR_VERSION == 2
CORBA::Exception::Exception (void)
: id_ (),
name_ ()
Expand Down
3 changes: 0 additions & 3 deletions tests/DCPS/PersistentInfoRepo/Publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,9 @@ ACE_TMAIN(int argc, ACE_TCHAR *argv[])
// Initialize samples
::Xyz::Foo message;

char number[20];

std::cerr << pid << "Pub Stage " << stage << " sending id=" << id << "\n";
for (int i = 0; i<msg_count; ++i) {
// Prepare next sample
sprintf(number, "foo %d", i);
message.key = msg_count;
message.c = (char)i;
message.x = id;
Expand Down
23 changes: 11 additions & 12 deletions tests/DCPS/Reliability/pub/Publisher.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
/*
*
*
* Distributed under the OpenDDS License.
* See: http://www.opendds.org/license.html
*/

#include "Boilerplate.h"
#include <dds/DCPS/Service_Participant.h>

#include <model/Sync.h>
#include <stdexcept>
#include <iostream>

#include "dds/DCPS/StaticIncludes.h"
#include <dds/DCPS/Service_Participant.h>
#include <dds/DCPS/SafetyProfileStreams.h>
#include <dds/DCPS/StaticIncludes.h>
#ifdef ACE_AS_STATIC_LIBS
#include <dds/DCPS/transport/rtps_udp/RtpsUdp.h>
# include <dds/DCPS/transport/rtps_udp/RtpsUdp.h>
#endif

#include <stdexcept>
#include <iostream>

using namespace examples::boilerplate;

int
Expand Down Expand Up @@ -61,12 +62,10 @@ ACE_TMAIN(int argc, ACE_TCHAR *argv[])
// Initialize samples
Reliability::Message message;

char number[20];

for (int i = 0; i<msg_count; ++i) {
for (int i = 0; i < msg_count; ++i) {
// Prepare next sample
sprintf(number, "foo %d", i);
message.id = CORBA::string_dup(number);
const OpenDDS::DCPS::String number = "foo " + OpenDDS::DCPS::to_dds_string(i);
message.id = CORBA::string_dup(number.c_str());
message.name = "foo";
message.count = (long)i;
message.expected = msg_count;
Expand Down
51 changes: 25 additions & 26 deletions tests/DCPS/StaticDiscovery/StaticDiscoveryTest.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
#include "TestMsgTypeSupportImpl.h"
#include "DataReaderListenerImpl.h"

#include "dds/DCPS/Service_Participant.h"
#include "dds/DCPS/Marked_Default_Qos.h"
#include "dds/DCPS/BuiltInTopicUtils.h"
#include "dds/DCPS/WaitSet.h"

#include "dds/DCPS/transport/framework/TransportExceptions.h"
#include "dds/DCPS/transport/framework/TransportRegistry.h"

#include "dds/DdsDcpsInfrastructureC.h"
#include "dds/DdsDcpsCoreTypeSupportImpl.h"
#include "dds/DCPS/GuidConverter.h"
#include "dds/DCPS/DataReaderImpl.h"
#include "dds/DCPS/DataWriterImpl.h"
#include "tests/Utils/StatusMatching.h"

#include "dds/DCPS/StaticIncludes.h"
#include <tests/Utils/StatusMatching.h>

#include <dds/DCPS/Service_Participant.h>
#include <dds/DCPS/Marked_Default_Qos.h>
#include <dds/DCPS/BuiltInTopicUtils.h>
#include <dds/DCPS/WaitSet.h>
#include <dds/DCPS/SafetyProfileStreams.h>
#include <dds/DCPS/GuidConverter.h>
#include <dds/DCPS/DataReaderImpl.h>
#include <dds/DCPS/DataWriterImpl.h>
#include <dds/DCPS/transport/framework/TransportExceptions.h>
#include <dds/DCPS/transport/framework/TransportRegistry.h>

#include <dds/DdsDcpsInfrastructureC.h>
#include <dds/DdsDcpsCoreTypeSupportImpl.h>

#include <dds/DCPS/StaticIncludes.h>
#ifdef ACE_AS_STATIC_LIBS
#include "dds/DCPS/transport/rtps_udp/RtpsUdp.h"
# include <dds/DCPS/transport/rtps_udp/RtpsUdp.h>
#endif

#include "ace/Arg_Shifter.h"
#include "ace/OS_NS_stdlib.h"
#include "ace/OS_NS_unistd.h"
#include <ace/Arg_Shifter.h>
#include <ace/OS_NS_stdlib.h>
#include <ace/OS_NS_unistd.h>

/*
NOTE: The messages may not be processed by the reader in this test.
Expand Down Expand Up @@ -91,9 +92,8 @@ class WriterTask : public ACE_Task_Base {
unsigned long binary_id = static_cast<unsigned long>(fromhex(writers_[thread_id], 2))
+ (256 * static_cast<unsigned long>(fromhex(writers_[thread_id], 1)))
+ (256 * 256 * static_cast<unsigned long>(fromhex(writers_[thread_id], 0)));
char config_name_buffer[16];
sprintf(config_name_buffer, "Config%lu", binary_id);
OpenDDS::DCPS::TransportRegistry::instance()->bind_config(config_name_buffer, publisher);
const OpenDDS::DCPS::String config_name = "Config" + OpenDDS::DCPS::to_dds_string(binary_id);
OpenDDS::DCPS::TransportRegistry::instance()->bind_config(config_name.c_str(), publisher);

DDS::DataWriterQos qos;
publisher->get_default_datawriter_qos(qos);
Expand Down Expand Up @@ -350,9 +350,8 @@ ACE_TMAIN(int argc, ACE_TCHAR *argv[])
unsigned long binary_id = static_cast<unsigned long>(fromhex(*pos, 2))
+ (256 * static_cast<unsigned long>(fromhex(*pos, 1)))
+ (256 * 256 * static_cast<unsigned long>(fromhex(*pos, 0)));
char config_name_buffer[16];
sprintf(config_name_buffer, "Config%lu", binary_id);
OpenDDS::DCPS::TransportRegistry::instance()->bind_config(config_name_buffer, subscriber);
const OpenDDS::DCPS::String config_name = "Config" + OpenDDS::DCPS::to_dds_string(binary_id);
OpenDDS::DCPS::TransportRegistry::instance()->bind_config(config_name.c_str(), subscriber);

DDS::DataReaderQos qos;
subscriber->get_default_datareader_qos(qos);
Expand Down
2 changes: 1 addition & 1 deletion tests/DCPS/XTypes/Subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ struct ReadTest {
}
// TODO: the duplicate shouldn't be required, but a direct assignment isn't
// incrementing the reference count.
// http://bugzilla.dre.vanderbilt.edu/show_bug.cgi?id=3942
// https://github.com/DOCGroup/ACE_TAO/issues/2037
dd = DDS::DynamicData::_duplicate(seq[0]);
return true;
#endif
Expand Down
24 changes: 11 additions & 13 deletions tests/unit-tests/dds/DCPS/MemoryPool.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <gtest/gtest.h>

#include "dds/DCPS/MemoryPool.h"
#include "ace/Log_Msg.h"
#include <dds/DCPS/MemoryPool.h>
#include <dds/DCPS/SafetyProfileStreams.h>

#include <ace/Log_Msg.h>

#include <string.h>
#include <iostream>
Expand Down Expand Up @@ -989,31 +991,27 @@ class MemoryPoolTest {
if (log) {
printf("Pool ptr %zx end %zx\n", (size_t)pool.pool_ptr_,
(size_t)pool_end);
}
}

// Check all allocs in positional order and not overlapping
alloc = reinterpret_cast<AllocHeader*>(pool.pool_ptr_);
while (pool.includes(alloc)) {
if (log) {

int smlr_index = -1;
int lrgr_index = -1;
char lrgr_buff[32];
char smlr_buff[32];
String smaller = "[ ]";
String larger = "[ ]";

FreeHeader* free_header = alloc->is_free() ?
reinterpret_cast<FreeHeader*>(alloc) : NULL;
if (free_header) {
FreeMap::const_iterator found;
found = free_map.find(free_header->smaller_free(pool.pool_ptr_));
if (found != free_map.end()) {
smlr_index = found->second;
sprintf(smlr_buff, "[%2d]", smlr_index);
smaller = "[" + to_dds_string(found->second) + "]";
}
found = free_map.find(free_header->larger_free(pool.pool_ptr_));
if (found != free_map.end()) {
lrgr_index = found->second;
sprintf(lrgr_buff, "[%2d]", lrgr_index);
larger = "[" + to_dds_string(found->second) + "]";
}
}
printf(
Expand All @@ -1023,8 +1021,8 @@ class MemoryPoolTest {
(alloc == pool.largest_free_ ? "FREE!" : "free ") : " ",
(size_t)alloc,
(size_t)alloc->ptr(),
lrgr_index >= 0 ? lrgr_buff : "[ ]",
smlr_index >= 0 ? smlr_buff : "[ ]",
larger.c_str(),
smaller.c_str(),
alloc->size(),
alloc->prev_size()
);
Expand Down
12 changes: 9 additions & 3 deletions tools/modeling/tests/MessengerMC/fs_signal.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#include "fs_signal.h"
#include <fstream>

#include <dds/DCPS/SafetyProfileStreams.h>

#include <ace/OS_NS_unistd.h>

FileSystemSignal::FileSystemSignal(int id) : _id(id) {
sprintf(_file_name, "fs_signal_%d", _id);
#include <fstream>

FileSystemSignal::FileSystemSignal(int id)
: _id(id)
, _file_name("fs_signal_" + to_dds_string(id)
{
}

void FileSystemSignal::signal() {
Expand Down
4 changes: 3 additions & 1 deletion tools/modeling/tests/MessengerMC/fs_signal.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef FS_SIGNAL_H
#define FS_SIGNAL_H

#include <dds/DCPS/PoolAllocator.h>

class FileSystemSignal {
public:
FileSystemSignal(int id);
Expand All @@ -10,7 +12,7 @@ class FileSystemSignal {

private:
int _id;
char _file_name[24];
OpenDDS::DCPS::String _file_name;

bool exists();
};
Expand Down
23 changes: 19 additions & 4 deletions tools/scripts/update_gitignore.pl
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
#!/usr/bin/env perl

use File::Basename;
use strict;
use warnings;

use File::Basename;
use FindBin;
use Getopt::Long;

my $root = "$FindBin::RealBin/../..";
my $wildcard_replace = undef;
my @sort_existing = ();
GetOptions(
'r|root=s' => \$root,
'w|wildcard-replace=s' => \$wildcard_replace,
's|sort-existing=s' => \@sort_existing,
) or die("Invalid options");

chdir($root) or die("Couldn't chdir to $root: $!");

my %dirs;
my %dirs = map { $_ => [] } @sort_existing;

open GIT, "git status --porcelain |";
while (<GIT>) {
chomp;
next unless /^\?\?\s+(\S+)/;
my @fp = fileparse $1;
if (scalar @ARGV) {
$fp[0] =~ s/$ARGV[0]/*/g;
if (defined($wildcard_replace)) {
$fp[0] =~ s/$wildcard_replace/*/g;
}
push(@{$dirs{$fp[1]}}, '/' . $fp[0]);
}
Expand Down

0 comments on commit 644a52f

Please sign in to comment.