Skip to content

Instantly share code, notes, and snippets.

@pix
Created May 12, 2011 15:20
Show Gist options
  • Save pix/968723 to your computer and use it in GitHub Desktop.
Save pix/968723 to your computer and use it in GitHub Desktop.
delete-null-pointer-checks
all:
@echo "gcc-4.4 && -fdelete-null-pointer-checks"
@gcc-4.4 -O2 -ggdb -Wall -Wundef -fno-strict-aliasing -fno-common -fdelete-null-pointer-checks test-deref.c -o test-deref
@./test-deref || true &&
@echo "gcc-4.5 && -fdelete-null-pointer-checks"
@gcc-4.5 -O2 -ggdb -Wall -Wundef -fno-strict-aliasing -fno-common -fdelete-null-pointer-checks test-deref.c -o test-deref
@./test-deref || true
@echo "gcc-4.4 && -fno-delete-null-pointer-checks"
@gcc-4.4 -O2 -ggdb -Wall -Wundef -fno-strict-aliasing -fno-common -fno-delete-null-pointer-checks test-deref.c -o test-deref
@./test-deref || true
@echo "gcc-4.5 && -fno-delete-null-pointer-checks"
@gcc-4.5 -O2 -ggdb -Wall -Wundef -fno-strict-aliasing -fno-common -fno-delete-null-pointer-checks test-deref.c -o test-deref
@./test-deref || true
#include <stdio.h>
struct agnx_priv {
char demo;
};
struct ieee80211_hw {
struct agnx_priv *priv;
};
struct pci_dev {
struct ieee80211_hw* dev;
};
struct ieee80211_hw* pci_get_drvdata(struct pci_dev *pdev) {
if(!pdev)
return NULL;
return pdev->dev;
}
static void agnx_pci_remove (struct pci_dev *pdev)
{
struct ieee80211_hw *dev = pci_get_drvdata(pdev);
struct agnx_priv *priv = dev->priv;
if (!dev) return;
// This will segfault if the previous if is optimized
printf("%c\n", priv->demo);
}
int main(int argc, char **argv)
{
// (struct pci_dev *)argv[1] is just to avoid compiler optimisations
// =~ NULL if no args are passed.
struct pci_dev * pdev = (struct pci_dev *)argv[1];
agnx_pci_remove(pdev);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment