Bug 54366 - Unreachable code at tree/pkg.c#n1313 (rpmvercmp())
Summary: Unreachable code at tree/pkg.c#n1313 (rpmvercmp())
Status: RESOLVED NOTOURBUG
Alias: None
Product: pkg-config
Classification: Unclassified
Component: src (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: Tollef Fog Heen
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-01 22:49 UTC by Michał Górny
Modified: 2012-10-13 16:20 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Michał Górny 2012-09-01 22:49:21 UTC
In the rpmvercmp() function in tree/pkg.c, I believe that the condition on line 1313 never evaluates to true, effectively the relevant branch is never reached.

1. The while loop on l1281 ensures that both 'one' and 'two' are alphanumeric:

    while (*one && *two) {
	while (*one && !isalnum((guchar)*one)) one++;
	while (*two && !isalnum((guchar)*two)) two++;

	/* If we ran to the end of either, we are finished with the loop */
	if (!(*one && *two)) break;

2. The code block starting on l1294 always increases str1 at least by one. The initial condition for 'if' is the same as the condition in first 'while' iteration. Effectively, the first while always evaluates to true and str1 is always incremented.

	if (isdigit((guchar)*str1)) {
	    while (*str1 && isdigit((guchar)*str1)) str1++;
	    while (*str2 && isdigit((guchar)*str2)) str2++;
	    isnum = 1;
	} else {
	    while (*str1 && isalpha((guchar)*str1)) str1++;

3. Thus, it is impossible for the condition on l1313 to be true, since str1 being always incremented, it can no longer be equal to one.

	if (one == str1) return -1;	/* arbitrary */
Comment 1 Dan Nicholson 2012-10-13 16:20:08 UTC
Your analysis looks correct, and indeed the actual upstream commit that added it has a comment that this can't happen.

http://rpm.org/gitweb?p=rpm.git;a=commitdiff;h=40d26f7b

However, I'd rather keep it as I think our divergence from upstream should be as minimal as possible. I have a branch I'd like to push that makes all the formatting and comments exactly the same so I can tell exactly how different we are from upstream rpmvercmp.

Since the code isn't hurting anything, I'd like to keep it. I encourage you to take your analysis to the rpm devs, though. I'd be happy to pull that into pkg-config if upstream likes it.

http://www.rpm.org/report

Thanks.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.