Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 29, 2025

Plan for implementing dmlist_find_next

  • Add dmlist_find_next function declaration in include/dmlist.h
  • Implement dmlist_find_next function in src/dmlist.c
  • Add tests for dmlist_find_next in tests/test_simple.c
  • Build and test the implementation
  • Run code review and address feedback
  • Run security check with CodeQL
  • Refactor dmlist_find to use dmlist_find_next wrapper

Summary

Successfully implemented dmlist_find_next function and refactored dmlist_find to eliminate code duplication.

Implementation Details:

  • Function signature: void* dmlist_find_next(dmlist_context_t* ctx, const void* last_found, const void* data, dmlist_compare_func_t compare_func)
  • Behavior:
    • If last_found is NULL, starts searching from the beginning of the list
    • If last_found is not NULL, validates it exists in the list and continues searching from the next node
    • Returns NULL if last_found is not found in the list (security feature)
    • Returns pointer to found data or NULL if not found
  • Code optimization: dmlist_find now simply calls dmlist_find_next(ctx, NULL, data, compare_func), eliminating duplicate code

Test Coverage:

  • Finding first occurrence with NULL last_found
  • Finding multiple consecutive occurrences
  • Returning NULL when no more matches exist
  • Validating behavior with invalid last_found pointer
  • Ensuring consistency with dmlist_find when last_found is NULL

Quality Checks:

  • ✅ All tests pass
  • ✅ Code review completed and feedback addressed
  • ✅ CodeQL security scan: 0 vulnerabilities found
  • ✅ Comparison function moved to file scope (C best practices)
  • ✅ Input validation added for edge cases
  • ✅ Code duplication eliminated
Original prompt

This section details on the original issue you should resolve

<issue_title>Dodać funkcję find_next</issue_title>
<issue_description>Potrzebna jest funkcja dmlist_find_next, która będzie podobna do dmlist_find, ale z tą różnicą, że będzie można przekazać do niej pointer na ostatni znaleziony item i rozpocząć szukanie od niego. Jeśli ostatni jest NULL, to zaczyna od początku listy. </issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits December 29, 2025 14:14
Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
… validate last_found

Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
@JohnAmadis JohnAmadis marked this pull request as ready for review December 29, 2025 14:19
Copilot AI changed the title [WIP] Add find_next function to DMLIST Add dmlist_find_next for resumable list search Dec 29, 2025
Copilot AI requested a review from JohnAmadis December 29, 2025 14:20
Copy link
Contributor

@JohnAmadis JohnAmadis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot popraw to proszę

return NULL;
}

DMOD_INPUT_API_DECLARATION( dmlist, 1.0, void*, _find_next, ( dmlist_context_t* ctx, const void* last_found, const void* data, dmlist_compare_func_t compare_func ) )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

przecież teraz zwykły find może być po prostu wrapperem na tę funkcję

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Masz rację! Zrefaktorowałem kod - teraz dmlist_find jest prostym wrapperem który wywołuje dmlist_find_next(ctx, NULL, data, compare_func). To eliminuje duplikację kodu. (ac66e8c)

Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 29, 2025

@copilot popraw to proszę

Poprawione! Zrefaktorowałem dmlist_find żeby był wrapperem dla dmlist_find_next, co eliminuje duplikację kodu. Wszystkie testy przechodzą pomyślnie. (ac66e8c)

Copilot AI requested a review from JohnAmadis December 29, 2025 14:26
@JohnAmadis JohnAmadis merged commit 361f304 into master Dec 29, 2025
2 checks passed
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

Successfully merging this pull request may close these issues.

Dodać funkcję find_next

2 participants