Fundamentals 4 min read

Common Return Code Bugs in Function Testing and Their Solutions

The article examines two typical return‑code bugs encountered during white‑box testing—one where error paths mistakenly return a success code and another where callers check the wrong value—explaining their causes and offering concrete remediation guidelines to improve error handling.

360 Quality & Efficiency
360 Quality & Efficiency
360 Quality & Efficiency
Common Return Code Bugs in Function Testing and Their Solutions

This article discusses two common bugs related to function return codes encountered during white‑box testing, explains why they occur, and provides concrete remediation steps.

Return Code Bug 1 : In an exceptional scenario the function returns the success code QCONF_OK because the variable ret is initialized to QCONF_OK and never updated when an error occurs, causing the caller to treat the error as a normal flow.

Solution : Assign a distinct return value for each error branch so the caller can differentiate success from failure.

Return Code Bug 2 : The caller checks for -1 to detect failure, but the callee never returns -1 (it uses macros for all error codes), making the failure‑handling block unreachable.

Solution : Change the condition to if (QCONF_OK != ret) or use a unified macro for all non‑normal return codes.

Summary of Recommendations :

Check Rule

Typical Bug Points

Advice

Ensure every branch returns the correct code.

Missing assignment to the return‑code variable in complex branches.

Standardize initialization and assign a value in each error path.

Caller handling.

Make sure the callee defines all error paths and uses macros instead of raw numbers; update caller checks when return codes change.

software testingbugerror handlingreturn codewhite-box testing
360 Quality & Efficiency
Written by

360 Quality & Efficiency

360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.