Bug 62065 - poptGetContext declared incorrectly in popt.h
poptGetContext declared incorrectly in popt.h
Status: CLOSED WORKSFORME
Product: Red Hat Linux
Classification: Retired
Component: popt (Show other bugs)
7.1
i386 Linux
medium Severity low
: ---
: ---
Assigned To: Jeff Johnson
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2002-03-27 00:52 EST by David Lloyd
Modified: 2008-05-01 11:38 EDT (History)
0 users

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


Attachments (Terms of Use)

  None (edit)
Description David Lloyd 2002-03-27 00:52:36 EST
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 09:54:59 EST
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.