Skip to content

Conversation

@pypingou
Copy link
Contributor

Summary

  • Fix multiple dangling reference issues across configuration parsing and service management components
  • Suppress false positive uninitialized variable warnings in LoLa bindings
  • Improve code safety and compatibility with newer GCC versions

Changes Made

  • Instance Identifier: Fix dangling reference in JSON parsing (instance_identifier.cpp:62-74)
  • Service Management: Fix dangling reference in LoLa service UID map conversion
  • Configuration Parser: Fix multiple dangling references in configuration parser
  • Tracing: Fix dangling references in tracing filter configuration parser
  • Service Factory: Fix dangling reference in skeleton service element factory template
  • LoLa Bindings: Suppress false positive uninitialized variable warnings

@LittleHuba
Copy link
Contributor

Thanks for adapting the suppressions. From my previous review two conversations remain open.
Also please consider unit test coverage for your adaptations. Since we now don't forcibly terminate in all cases, this will have an impact on coverage.

We are working on a workflow for coverage metrics, so feel free to wait until we have tooling available.

@pypingou
Copy link
Contributor Author

Thanks for adapting the suppressions. From my previous review two conversations remain open.

Yes, though I'm not entirely sure what you'd like me to do, you've said:

I propose, that we fail the configuration parsing if there is an error in the schema of the file (independent on mandatory/optional configs).
This is actually what the current code already does. But adding some logs would be a nice addition, to actually help the user with fixing his mistakes.

I believe the errors now are a little more self-descriptive about which value failed to be parsed and you say the code already fails on error in the schema.

So did I miss something?

I'll take a look at the test/coverage questions

@LittleHuba
Copy link
Contributor

Sorry for not being clear.
What I meant with my comment is, that the code on the main branch will terminate if the configuration is broken.
You have branches in your changes where instead of terminating you continue on. The schema only checks at build time. We also need this safeguard at runtime.

So in short, please check that your added/changed error branches terminate, with a SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD(false) after writing a log message.

That way we don't have any behavioral change with your PR but still improve the current error handling.

@pypingou
Copy link
Contributor Author

Sorry for not being clear. What I meant with my comment is, that the code on the main branch will terminate if the configuration is broken. You have branches in your changes where instead of terminating you continue on. The schema only checks at build time. We also need this safeguard at runtime.

So in short, please check that your added/changed error branches terminate, with a SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD(false) after writing a log message.

That way we don't have any behavioral change with your PR but still improve the current error handling.

ah ok, thanks for clarifying I'll do these changes (though likely next week at this point)

@pypingou
Copy link
Contributor Author

pypingou commented Dec 8, 2025

Ok commits adjusted to terminate with a SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD(false) when the configuration is invalid.

I see this conflicts now, I'll see if I can fix thoses

@pypingou
Copy link
Contributor Author

pypingou commented Dec 8, 2025

Unit-tests added, let's see what CI says :)

@LittleHuba
Copy link
Contributor

Seems like the CI is not yet happy. Could you please fix the build errors? Once the checks are green, I'll do another review.

@pypingou pypingou force-pushed the port_newer_gcc branch 3 times, most recently from 28ba8ac to bd79f0d Compare December 9, 2025 11:32
LittleHuba

This comment was marked as duplicate.

@pypingou pypingou force-pushed the port_newer_gcc branch 2 times, most recently from 8718b2b to 0c1543f Compare December 10, 2025 12:56
@LittleHuba
Copy link
Contributor

You missed one terminate call and the tests must be integrated with the existing test suites. Otherwise, this is okay now.

@pypingou
Copy link
Contributor Author

pypingou commented Jan 9, 2026

You missed one terminate call and the tests must be integrated with the existing test suites. Otherwise, this is okay now.

Sorry it took so long, fixed the missing terminal call and I'll see if I can improve the test suite integration

pypingou and others added 2 commits January 9, 2026 14:51
GCC 15 introduced enhanced dangling reference detection that caught
an unsafe method chaining pattern in the instance identifier parsing:

  const auto& json_object = std::move(json_result).value().As<json::Object>().value().get();

This creates a dangling reference because:
1. .value() returns a temporary object
2. .As<json::Object>() returns another temporary
3. .value().get() returns a reference to data in the temporary
4. The temporary is destroyed at the end of the statement

Fixed by breaking the chain into proper lifetime management:
- Store intermediate results explicitly
- Add proper error checking at each step
- Ensure references point to stable objects

This eliminates undefined behavior that could cause runtime failures
with newer compilers or different optimization levels.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Resolved GCC 15 dangling reference warning in ConvertJsonToUidMap function
where method chaining on temporary JSON objects created unsafe references:

  const auto& uids_json = it.second.As<score::json::List>().value().get();

The issue occurs because:
- .As<score::json::List>() returns a temporary Result<List>
- .value() returns a temporary List&&
- .get() returns a reference to the temporary List
- The temporary is destroyed immediately, leaving a dangling reference

Fixed by:
- Storing the Result<List> explicitly before accessing
- Adding proper error handling for invalid JSON structure
- Ensuring the reference points to a stable object

This prevents potential crashes when processing LoLa service configuration
with newer compiler versions.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
pypingou and others added 3 commits January 9, 2026 14:52
Systematically resolved numerous GCC 15 dangling reference warnings
throughout the configuration parsing system. All instances followed
the same unsafe pattern of method chaining on temporary JSON objects:

  const auto& obj = json.As<Type>().value().get();  // UNSAFE

This pattern creates undefined behavior because:
- JSON parsing returns temporary Result<T> objects
- Method chaining (.value().get()) on temporaries creates dangling refs
- The temporary Result is destroyed before the reference is used

Fixed in functions:
- ParseInstanceSpecifier()
- ParseServiceTypeName()
- ParseVersion()
- ParseAsilLevel()
- ParseShmSizeCalcMode()
- ParseAllowedUser()
- ParseLolaEventInstanceDeployment()
- ParseLolaFieldInstanceDeployment()
- ParseServiceInstanceDeployments()
- ParseServiceInstances()
- ParseServiceElementTracingEnabled()
- ParsePermissionChecks()
- ParseLolaServiceInstanceDeployment()

Each fix follows the same pattern:
1. Store Result<T> explicitly
2. Check .has_value() before accessing
3. Get reference from stable stored result

This eliminates undefined behavior and ensures robust configuration
parsing across all compiler versions and optimization levels.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Resolved multiple GCC 15 dangling reference warnings in the tracing
configuration system where JSON parsing used unsafe method chaining
patterns on temporary objects.

Functions fixed:
- ParseEvent(): Event configuration parsing
- ParseEvents(): Event list processing
- ParseField(): Field configuration parsing
- ParseFields(): Field list processing
- ParseService(): Service configuration parsing
- ParseServices(): Top-level service parsing
- AddTracePointsFromSubObject(): Trace point extraction
- WarnNotImplementedTracePointsFromSubObject(): Warning generation

The core issue was the same pattern throughout:
  const auto& obj = json.As<Object>().value().get();

This creates dangling references because the Result<Object> temporary
is destroyed before the reference is used, leading to undefined behavior.

Each fix properly manages object lifetimes by:
1. Storing JSON parsing results explicitly
2. Checking success before accessing data
3. Maintaining stable references to stored objects

This ensures the tracing configuration system works reliably with
modern compilers while maintaining all existing functionality.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Resolved final GCC 15 dangling reference warning in the template-heavy
skeleton service element binding factory where string_view parameters
were being converted to temporary std::string objects:

  GetServiceElementInstanceDeployment(deployment, std::string{service_element_name});
  GetServiceElementId(deployment, std::string{service_element_name});

The issue: std::string{service_view} creates a temporary string, and if
the called functions return references to data within that temporary,
the reference becomes dangling when the temporary is destroyed.

Fixed by:
- Creating explicit string variable from string_view
- Reusing the same string for both function calls
- Ensuring all references point to the stable string object

This eliminates the last dangling reference in the codebase and ensures
the skeleton binding system works correctly with all compiler versions
and optimization levels.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@pypingou pypingou force-pushed the port_newer_gcc branch 2 times, most recently from 2c5bdee to d23ca9a Compare January 9, 2026 15:43
pypingou and others added 3 commits January 9, 2026 16:46
Tests the fixes for commits:
- 0f308cc "Fix multiple dangling references in configuration parser"
- 8b9cbc7 "Fix dangling reference in LoLa service UID map conversion"

Configuration Parser Tests:
Validates proper error handling in all ParseXXX functions that were
fixed to prevent dangling references when processing malformed JSON:

- ParseInstanceSpecifier, ParseServiceTypeName, ParseVersion
- ParseAsilLevel, ParseShmSizeCalcMode, ParseAllowedUser
- ParsePermissionChecks, ParseServiceElementTracingEnabled
- And other parsing functions with the unsafe pattern

LoLa Service UID Map Tests:
Specifically tests the ConvertJsonToUidMap function fix from:
  const auto& uids = it.second.As<List>().value().get();  // UNSAFE
To:
  auto uids_result = it.second.As<List>();
  if (!uids_result.has_value()) { /* error handling */ }
  const auto& uids = uids_result.value().get();  // SAFE

Both test suites verify that the new explicit lifetime management
prevents undefined behavior while maintaining proper error reporting
through ConfigurationErrc::kInvalidJson.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
Added comprehensive test coverage for the configuration parser dangling
reference fixes that prevent GCC 15 warnings. These tests validate the
new error handling paths introduced when fixing the unsafe pattern:
  const auto& obj = json.As<Type>().value().get();  // UNSAFE
To the safe pattern:
  auto obj_result = json.As<Type>();
  if (!obj_result.has_value()) { /* error handling */ }
  const auto& obj = obj_result.value().get();  // SAFE

Test coverage includes:
- ParseInstanceSpecifier() error handling for invalid JSON
- ParseServiceTypeName() validation with malformed inputs
- ParseVersion() handling of invalid version objects
- ParseServiceInstanceDeployments() deployment validation
- ParseAsilLevel() graceful handling of invalid types
- ParseShmSizeCalcMode() error reporting for invalid modes
- ParseAllowedUser() validation of user configurations
- ParsePermissionChecks() default value handling

Tests exercise the error handling through the public Parse() function
with various malformed JSON configurations that trigger the specific
error paths added in the dangling reference fixes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
Update LolaServiceUidMapTest to follow established patterns used by other
configuration tests:
- Inherit from ConfigurationStructsFixture instead of raw ::testing::Test
- Add dependency on configuration_test_resources
- Extract common setup code into CreateBaseConfigObject() helper
- Remove duplicated configuration object initialization across tests

Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
@LittleHuba
Copy link
Contributor

The QNX build is currently broken due to infrastructure issues. So failures in those two jobs can be ignored.

@pypingou
Copy link
Contributor Author

pypingou commented Jan 9, 2026

The QNX build is currently broken due to infrastructure issues. So failures in those two jobs can be ignored.

Thanks for confirming, I was trying to see if that was related to my changes but it didn't seem like :)

@LittleHuba LittleHuba added the import-started-do-not-modify Import of the PR was started. No further modifications allowed. label Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

import-started-do-not-modify Import of the PR was started. No further modifications allowed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants