Skip to content

Instantly share code, notes, and snippets.

@elieux
Last active January 28, 2019 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elieux/02ccb2a79f14b21f2052d568b378f81e to your computer and use it in GitHub Desktop.
Save elieux/02ccb2a79f14b21f2052d568b378f81e to your computer and use it in GitHub Desktop.
popt-1.16 opt != NULL patch
--- original/popt-1.16/popt.c 2010-01-19 01:39:10.000000000 +0100
+++ patched/popt-1.16/popt.c 2019-01-28 21:49:43.543620300 +0100
@@ -75,8 +75,7 @@
/*@globals internalState@*/
/*@modifies internalState@*/
{
- if (opt != NULL)
- for (; opt->longName || opt->shortName || opt->arg; opt++) {
+ for (; opt != NULL && (opt->longName || opt->shortName || opt->arg); opt++) {
poptArg arg = { .ptr = opt->arg };
if (arg.ptr)
switch (poptArgType(opt)) {
@@ -99,8 +98,7 @@
/*@globals internalState@*/
/*@modifies internalState@*/
{
- if (opt != NULL)
- for (; opt->longName || opt->shortName || opt->arg; opt++) {
+ for (; opt != NULL && (opt->longName || opt->shortName || opt->arg); opt++) {
poptArg arg = { .ptr = opt->arg };
if (arg.ptr)
switch (poptArgType(opt)) {
@@ -129,8 +127,7 @@
const struct poptOption * cbopt = NULL;
poptArg cbarg = { .ptr = NULL };
- if (opt != NULL)
- for (; opt->longName || opt->shortName || opt->arg; opt++) {
+ for (; opt != NULL && (opt->longName || opt->shortName || opt->arg); opt++) {
poptArg arg = { .ptr = opt->arg };
switch (poptArgType(opt)) {
case POPT_ARG_INCLUDE_TABLE: /* Recurse on included sub-tables. */
@@ -591,7 +587,7 @@
if (LF_ISSET(ONEDASH) && !shortName && (longName && *longName == '\0'))
shortName = '-';
- for (; opt->longName || opt->shortName || opt->arg; opt++) {
+ for (; opt != NULL && (opt->longName || opt->shortName || opt->arg); opt++) {
poptArg arg = { .ptr = opt->arg };
switch (poptArgType(opt)) {
@@ -1023,7 +1021,7 @@
int poptSaveLong(long * arg, unsigned int argInfo, long aLong)
{
/* XXX Check alignment, may fail on funky platforms. */
- if (arg == NULL || (((unsigned long)arg) & (sizeof(*arg)-1)))
+ if (arg == NULL || (((intptr_t)arg) & (sizeof(*arg)-1)))
return POPT_ERROR_NULLARG;
if (aLong != 0 && LF_ISSET(RANDOM)) {
@@ -1056,7 +1054,7 @@
int poptSaveInt(/*@null@*/ int * arg, unsigned int argInfo, long aLong)
{
/* XXX Check alignment, may fail on funky platforms. */
- if (arg == NULL || (((unsigned long)arg) & (sizeof(*arg)-1)))
+ if (arg == NULL || (((intptr_t)arg) & (sizeof(*arg)-1)))
return POPT_ERROR_NULLARG;
if (aLong != 0 && LF_ISSET(RANDOM)) {
@@ -1089,7 +1087,7 @@
int poptSaveShort(/*@null@*/ short * arg, unsigned int argInfo, long aLong)
{
/* XXX Check alignment, may fail on funky platforms. */
- if (arg == NULL || (((unsigned long)arg) & (sizeof(*arg)-1)))
+ if (arg == NULL || (((intptr_t)arg) & (sizeof(*arg)-1)))
return POPT_ERROR_NULLARG;
if (aLong != 0 && LF_ISSET(RANDOM)) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment