diff --git a/require-ess/src/require.c b/require-ess/src/require.c index 87972619b8eca9c6db7d34471d0cfb83d3e3954d..6bd8866148d750aa21c5faeb188a48ca20367000 100644 --- a/require-ess/src/require.c +++ b/require-ess/src/require.c @@ -806,7 +806,7 @@ int libversionShow(const char *outfile) if (requireDebug) \ printf(__VA_ARGS__) -static int compareDigit(int found, int requested, char *name) +static int compareDigit(int found, int requested, const char *name) { debug("require: compareDigit: found %d, requested %d for digit %s\n", found, requested, name); if (found < requested) @@ -823,6 +823,35 @@ static int compareDigit(int found, int requested, char *name) return MATCH; } +static int compareNumericVersion(semver_t *sv_found, semver_t *sv_request, int already_matched) { + int match; + + match = compareDigit(sv_found->major, sv_request->major, "major"); + if (match != MATCH) + return match; + match = compareDigit(sv_found->minor, sv_request->minor, "minor"); + if (match != MATCH) + return match; + match = compareDigit(sv_found->patch, sv_request->patch, "patch"); + if (match != MATCH) + return match; + + if (sv_request->build == -1) + { + if (already_matched) + { + debug("require: compareVersions: No build number requested. Returning HIGHER\n"); + return HIGHER; + } + else + { + debug("require: compareVersions: No build number requested. Returning MATCH\n"); + return MATCH; + } + } + return compareDigit(sv_found->build, sv_request->build, "build"); +} + /* * Returns if the version <found> is higher than <request>. */ @@ -874,25 +903,9 @@ static int compareVersions(const char *found, const char *request, int already_m debug("require: compareVersions: Numeric version requested, test version found\n"); match = MISMATCH; } - else if ((match = compareDigit(sv_found->major, sv_request->major, "major")) != MATCH) - ; - else if ((match = compareDigit(sv_found->minor, sv_request->minor, "minor")) != MATCH) - ; - else if ((match = compareDigit(sv_found->patch, sv_request->patch, "patch")) != MATCH) - ; - else if (sv_request->build == -1) { - if (already_matched) - { - debug("require: compareVersions: No build number requested. Returning HIGHER\n"); - return HIGHER; - } - else - { - debug("require: compareVersions: No build number requested. Returning MATCH\n"); - return MATCH; - } - } else { - match = compareDigit(sv_found->build, sv_request->build, "build"); + else + { + match = compareNumericVersion(sv_found, sv_request, already_matched); } cleanup_semver(sv_found); cleanup_semver(sv_request);