Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1142 Include null terminator in string size constant
Browse files Browse the repository at this point in the history
Signed-off-by: Marika Lehmann <[email protected]>
  • Loading branch information
FerdinandSpitzschnueffler committed Feb 28, 2022
1 parent 8c39c3f commit 7b20fa7
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ hicpp-*,
-bugprone-easily-swappable-parameters,
-bugprone-branch-clone,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-not-null-terminated-result,
-concurrency-mt-unsafe,
-readability-named-parameter,
-readability-avoid-const-params-in-decls,
Expand Down Expand Up @@ -86,7 +87,7 @@ hicpp-*,
# -readability-function-cognitive-complexity
#
## is it working correctly? produces hard to understand warning
# -clang-analyzer-core.uninitialized.UndefReturn
# -clang-analyzer-core.uninitialized.UndefReturn
# -clang-analyzer-optin.cplusplus.VirtualCall
#
###########################################
Expand Down
4 changes: 2 additions & 2 deletions iceoryx_binding_c/include/iceoryx_binding_c/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ uint32_t iox_cfg_max_runtime_name_length();
/// @brief the maximum size of a node name string + \0 terminator
#define IOX_CONFIG_NODE_NAME_SIZE 101

/// @brief the maximum size of a service description string identifier
#define IOX_CONFIG_SERVICE_STRING_SIZE 100
/// @brief the maximum size of a service description string identifier + \0 terminator
#define IOX_CONFIG_SERVICE_STRING_SIZE 101

#endif // IOX_BINDING_C_CONFIG_H
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -23,9 +23,9 @@

typedef struct
{
char serviceString[IOX_CONFIG_SERVICE_STRING_SIZE + 1U]; // +1U for \0 terminator
char instanceString[IOX_CONFIG_SERVICE_STRING_SIZE + 1U];
char eventString[IOX_CONFIG_SERVICE_STRING_SIZE + 1U];
char serviceString[IOX_CONFIG_SERVICE_STRING_SIZE];
char instanceString[IOX_CONFIG_SERVICE_STRING_SIZE];
char eventString[IOX_CONFIG_SERVICE_STRING_SIZE];
} iox_service_description_t;

#endif
2 changes: 1 addition & 1 deletion iceoryx_binding_c/test/moduletests/test_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ TEST(iox_cfg, valuesAreCorrectlyConnected)
constexpr uint64_t ZERO_TERMINATOR_SIZE = 1U;
EXPECT_EQ(IOX_CONFIG_NODE_NAME_SIZE, iox::NodeName_t::capacity() + ZERO_TERMINATOR_SIZE);

EXPECT_EQ(IOX_CONFIG_SERVICE_STRING_SIZE, iox::capro::IdString_t::capacity());
EXPECT_EQ(IOX_CONFIG_SERVICE_STRING_SIZE, iox::capro::IdString_t::capacity() + ZERO_TERMINATOR_SIZE);
}
} // namespace
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Apex.AI Inc. All rights reserved.
// Copyright (c) 2021 - 2022 Apex.AI Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_examples/icediscovery_in_c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ To be able to search for services, we need to include:
#include "iceoryx_binding_c/service_discovery.h"
```

We create some stack storage for the service discovery and initialize it.
We create some storage for the service discovery and initialize it.

<!--[geoffrey][iceoryx_examples/icediscovery_in_c/iox_c_find_service.c][create service discovery handle]-->
```c
Expand Down
6 changes: 3 additions & 3 deletions iceoryx_examples/icediscovery_in_c/iox_c_find_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ void printSearchResult(const iox_service_description_t service)
//! [search function for all front devices]
void searchFrontDevices(const iox_service_description_t service, void* count)
{
if (strncmp("FrontLeft", service.instanceString, IOX_CONFIG_SERVICE_STRING_SIZE) == 0
|| strncmp("FrontRight", service.instanceString, IOX_CONFIG_SERVICE_STRING_SIZE) == 0)
if (strncmp(service.instanceString, "FrontLeft", IOX_CONFIG_SERVICE_STRING_SIZE) == 0
|| strncmp(service.instanceString, "FrontRight", IOX_CONFIG_SERVICE_STRING_SIZE) == 0)
{
++*(uint32_t*)count;
}
Expand All @@ -74,7 +74,7 @@ int main()
uint64_t missedServices = 0U;
uint64_t numberFoundServices = 0U;

const uint32_t WAIT_TIME_IN_MS = 1000;
const uint32_t WAIT_TIME_IN_MS = 1000U;

while (keepRunning)
{
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_examples/icediscovery_in_c/iox_c_offer_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int main()
cameraPublishers[3] = iox_pub_init(&cameraPublisherStorage[3], "Camera", "FrontRight", "Image", &options);
cameraPublishers[4] = iox_pub_init(&cameraPublisherStorage[4], "Camera", "BackLeft", "Image", &options);

const uint32_t WAIT_TIME_IN_MS = 1000;
const uint32_t WAIT_TIME_IN_MS = 1000U;
bool offer = false;
while (keepRunning)
{
Expand Down

0 comments on commit 7b20fa7

Please sign in to comment.