Bug 62065 - poptGetContext declared incorrectly in popt.h
Summary: poptGetContext declared incorrectly in popt.h
Status: CLOSED WORKSFORME
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: popt   
(Show other bugs)
Version: 7.1
Hardware: i386
OS: Linux
medium
low
Target Milestone: ---
Assignee: Jeff Johnson
QA Contact:
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2002-03-27 05:52 UTC by David Lloyd
Modified: 2008-05-01 15:38 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2002-03-27 05:52:41 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

Description David Lloyd 2002-03-27 05:52:36 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.8) Gecko/20020204

Description of problem:

I asked the Linux C Programming List about this definition:

| The definition is as follows:
| 
| /*@only@*/ poptContext poptGetContext(/*@keep@*/ const char * name,
|        int argc, /*@keep@*/ const char ** argv,
|        /*@keep@*/ const struct poptOption * options, int flags);

This declaration is wrong -- argv is not `const'.  The Standard
says:

    The parameters argc and argv and the strings pointed to by
    the argv array shall be modifiable by the program [...]

| int main(int argc, char *argv[]) {

This is a correct declaration.

| popt.c:14: warning: passing arg 3 of `poptGetContext' from
| incompatible pointer type

The diagnostic is correct, given the (incorrect) declaration in
popt.h -- but it's the header that is wrong.

Greg




Version-Release number of selected component (if applicable):
[lloy0076@isengard lloy0076]$ rpm -qa | grep popt
popt-1.6.2-8

How reproducible:
Always

Steps to Reproduce:

Compile this:

#include <stdio.h>
#include <stdlib.h>
#include <popt.h>

int main(int argc, char *argv[]) {
	int rc;
	char *name=malloc(sizeof(char)*256);

	struct poptOption opt[] = {
	{"username", 'u', POPT_ARG_STRING, name, 1}
	};

	poptContext context=poptGetContext(NULL, argc, argv, opt, 0);

	poptGetNextOpt(context);

	poptFreeContext(context);
	return 0;
}

Actual Results:  [lloy0076@isengard c]$ make
gcc -o popt `exec gnome-config --cflags gnome` `exec gnome-config --libs gnome`
popt.c
popt.c: In function `main':
popt.c:13: warning: passing arg 3 of `poptGetContext' from incompatible pointer
type

Expected Results:  
It should have been silent and just made an executable called "popt".

Additional info:

Comment 1 Jeff Johnson 2002-03-28 14:54:59 UTC
There's no easy solution to this in C.

Ideally, iIMHO, the prototype should be
	const char *const * argv
as that, indeed, is how the variable is
treated in poptGetContext. Attempting
	char *const * argv
creates a warning of a different sort, so
	char ** const argv
is used.


Note You need to log in before you can comment on or make changes to this bug.