Bug 784739 - Switch from NULL to nullptr in build/; r=ehsan
authorBirunthan Mohanathas <birunthan@mohanathas.com>
Mon, 11 Nov 2013 14:13:38 -0500
changeset 157309 365669affac77a990557f25f4d3a569fbc391d01
parent 157308 4ab109e8391a634c753db7b8c830c246a144194c
child 157310 ccca3c4247e1333b0695825b01bb420b67cf47e6
push idunknown
push userunknown
push dateunknown
reviewersehsan
bugs784739
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 784739 - Switch from NULL to nullptr in build/; r=ehsan
build/unix/elfhack/elf.cpp
build/unix/elfhack/elfhack.cpp
build/unix/elfhack/elfxx.h
build/win32/crashinject.cpp
build/win32/crashinjectdll/crashinjectdll.cpp
mozglue/build/arm.cpp
--- a/build/unix/elfhack/elf.cpp
+++ b/build/unix/elfhack/elf.cpp
@@ -101,17 +101,17 @@ void Elf_Rela_Traits::swap(T &t, R &r)
 
 static const Elf32_Shdr null32_section =
     { 0, SHT_NULL, 0, 0, 0, 0, SHN_UNDEF, 0, 0, 0 };
 
 Elf_Shdr null_section(null32_section);
 
 Elf_Ehdr::Elf_Ehdr(std::ifstream &file, char ei_class, char ei_data)
 : serializable<Elf_Ehdr_Traits>(file, ei_class, ei_data),
-  ElfSection(null_section, NULL, NULL)
+  ElfSection(null_section, nullptr, nullptr)
 {
     shdr.sh_size = Elf_Ehdr::size(ei_class);
 }
 
 Elf::Elf(std::ifstream &file)
 {
     if (!file.is_open())
         throw std::runtime_error("Error opening file");
@@ -171,58 +171,58 @@ Elf::Elf(std::ifstream &file)
 
     // Store these temporarily
     tmp_shdr = shdr;
     tmp_file = &file;
 
     // Fill sections list
     sections = new ElfSection *[ehdr->e_shnum];
     for (int i = 0; i < ehdr->e_shnum; i++)
-        sections[i] = NULL;
+        sections[i] = nullptr;
     for (int i = 1; i < ehdr->e_shnum; i++) {
-        if (sections[i] != NULL)
+        if (sections[i] != nullptr)
             continue;
         getSection(i);
     }
     Elf_Shdr s;
     s.sh_name = 0;
     s.sh_type = SHT_NULL;
     s.sh_flags = 0;
     s.sh_addr = 0;
     s.sh_offset = ehdr->e_shoff;
     s.sh_entsize = Elf_Shdr::size(e_ident[EI_CLASS]);
     s.sh_size = s.sh_entsize * ehdr->e_shnum;
     s.sh_link = 0;
     s.sh_info = 0;
     s.sh_addralign = (e_ident[EI_CLASS] == ELFCLASS32) ? 4 : 8;
-    shdr_section = new ElfSection(s, NULL, NULL);
+    shdr_section = new ElfSection(s, nullptr, nullptr);
 
     // Fake section for program headers
     s.sh_offset = ehdr->e_phoff;
     s.sh_addr = ehdr->e_phoff;
     s.sh_entsize = Elf_Phdr::size(e_ident[EI_CLASS]);
     s.sh_size = s.sh_entsize * ehdr->e_phnum;
-    phdr_section = new ElfSection(s, NULL, NULL);
+    phdr_section = new ElfSection(s, nullptr, nullptr);
 
     phdr_section->insertAfter(ehdr, false);
 
     sections[1]->insertAfter(phdr_section, false);
     for (int i = 2; i < ehdr->e_shnum; i++) {
         // TODO: this should be done in a better way
-        if ((shdr_section->getPrevious() == NULL) && (shdr[i]->sh_offset > ehdr->e_shoff)) {
+        if ((shdr_section->getPrevious() == nullptr) && (shdr[i]->sh_offset > ehdr->e_shoff)) {
             shdr_section->insertAfter(sections[i - 1], false);
             sections[i]->insertAfter(shdr_section, false);
         } else
             sections[i]->insertAfter(sections[i - 1], false);
     }
-    if (shdr_section->getPrevious() == NULL)
+    if (shdr_section->getPrevious() == nullptr)
         shdr_section->insertAfter(sections[ehdr->e_shnum - 1], false);
 
-    tmp_file = NULL;
-    tmp_shdr = NULL;
+    tmp_file = nullptr;
+    tmp_shdr = nullptr;
     for (int i = 0; i < ehdr->e_shnum; i++)
         delete shdr[i];
     delete[] shdr;
 
     eh_shstrndx = (ElfStrtab_Section *)sections[ehdr->e_shstrndx];
 
     // Skip reading program headers if there aren't any
     if (ehdr->e_phnum == 0)
@@ -275,37 +275,37 @@ Elf::Elf(std::ifstream &file)
 }
 
 Elf::~Elf()
 {
     for (std::vector<ElfSegment *>::iterator seg = segments.begin(); seg != segments.end(); seg++)
         delete *seg;
     delete[] sections;
     ElfSection *section = ehdr;
-    while (section != NULL) {
+    while (section != nullptr) {
         ElfSection *next = section->getNext();
         delete section;
         section = next;
     }
 }
 
 // TODO: This shouldn't fail after inserting sections
 ElfSection *Elf::getSection(int index)
 {
     if ((index < -1) || (index >= ehdr->e_shnum))
         throw std::runtime_error("Section index out of bounds");
     if (index == -1)
         index = ehdr->e_shstrndx; // TODO: should be fixed to use the actual current number
     // Special case: the section at index 0 is void
     if (index == 0)
-        return NULL;
+        return nullptr;
     // Infinite recursion guard
     if (sections[index] == (ElfSection *)this)
-        return NULL;
-    if (sections[index] == NULL) {
+        return nullptr;
+    if (sections[index] == nullptr) {
         sections[index] = (ElfSection *)this;
         switch (tmp_shdr[index]->sh_type) {
         case SHT_DYNAMIC:
             sections[index] = new ElfDynamic_Section(*tmp_shdr[index], tmp_file, this);
             break;
         case SHT_REL:
             sections[index] = new ElfRel_Section<Elf_Rel>(*tmp_shdr[index], tmp_file, this);
             break;
@@ -325,35 +325,35 @@ ElfSection *Elf::getSection(int index)
     }
     return sections[index];
 }
 
 ElfSection *Elf::getSectionAt(unsigned int offset)
 {
     for (int i = 1; i < ehdr->e_shnum; i++) {
         ElfSection *section = getSection(i);
-        if ((section != NULL) && (section->getFlags() & SHF_ALLOC) && !(section->getFlags() & SHF_TLS) &&
+        if ((section != nullptr) && (section->getFlags() & SHF_ALLOC) && !(section->getFlags() & SHF_TLS) &&
             (offset >= section->getAddr()) && (offset < section->getAddr() + section->getSize()))
             return section;
     }
-    return NULL;
+    return nullptr;
 }
 
 ElfSegment *Elf::getSegmentByType(unsigned int type, ElfSegment *last)
 {
     std::vector<ElfSegment *>::iterator seg;
     if (last) {
         seg = std::find(segments.begin(), segments.end(), last);
         ++seg;
     } else
         seg = segments.begin();
     for (; seg != segments.end(); seg++)
         if ((*seg)->getType() == type)
             return *seg;
-    return NULL;
+    return nullptr;
 }
 
 void Elf::removeSegment(ElfSegment *segment)
 {
     if (!segment)
         return;
     std::vector<ElfSegment *>::iterator seg;
     seg = std::find(segments.begin(), segments.end(), segment);
@@ -361,28 +361,28 @@ void Elf::removeSegment(ElfSegment *segm
         return;
     segment->clear();
     segments.erase(seg);
 }
 
 ElfDynamic_Section *Elf::getDynSection()
 {
     for (std::vector<ElfSegment *>::iterator seg = segments.begin(); seg != segments.end(); seg++)
-        if (((*seg)->getType() == PT_DYNAMIC) && ((*seg)->getFirstSection() != NULL) &&
+        if (((*seg)->getType() == PT_DYNAMIC) && ((*seg)->getFirstSection() != nullptr) &&
             (*seg)->getFirstSection()->getType() == SHT_DYNAMIC)
             return (ElfDynamic_Section *)(*seg)->getFirstSection();
 
-    return NULL;
+    return nullptr;
 }
 
 void Elf::normalize()
 {
     // fixup section headers sh_name; TODO: that should be done by sections
     // themselves
-    for (ElfSection *section = ehdr; section != NULL; section = section->getNext()) {
+    for (ElfSection *section = ehdr; section != nullptr; section = section->getNext()) {
         if (section->getIndex() == 0)
             continue;
         else
             ehdr->e_shnum = section->getIndex() + 1;
         section->getShdr().sh_name = eh_shstrndx->getStrIndex(section->getName());
     }
     ehdr->markDirty();
     // Check segments consistency
@@ -409,83 +409,83 @@ void Elf::normalize()
     ehdr->e_entry = eh_entry.getValue();
     ehdr->e_shstrndx = eh_shstrndx->getIndex();
 }
 
 void Elf::write(std::ofstream &file)
 {
     normalize();
     for (ElfSection *section = ehdr;
-         section != NULL; section = section->getNext()) {
+         section != nullptr; section = section->getNext()) {
         file.seekp(section->getOffset());
         if (section == phdr_section) {
             for (std::vector<ElfSegment *>::iterator seg = segments.begin(); seg != segments.end(); seg++) {
                 Elf_Phdr phdr;
                 phdr.p_type = (*seg)->getType();
                 phdr.p_flags = (*seg)->getFlags();
                 phdr.p_offset = (*seg)->getOffset();
                 phdr.p_vaddr = (*seg)->getAddr();
                 phdr.p_paddr = phdr.p_vaddr + (*seg)->getVPDiff();
                 phdr.p_filesz = (*seg)->getFileSize();
                 phdr.p_memsz = (*seg)->getMemSize();
                 phdr.p_align = (*seg)->getAlign();
                 phdr.serialize(file, ehdr->e_ident[EI_CLASS], ehdr->e_ident[EI_DATA]);
             }
         } else if (section == shdr_section) {
             null_section.serialize(file, ehdr->e_ident[EI_CLASS], ehdr->e_ident[EI_DATA]);
-            for (ElfSection *sec = ehdr; sec!= NULL; sec = sec->getNext()) {
+            for (ElfSection *sec = ehdr; sec!= nullptr; sec = sec->getNext()) {
                 if (sec->getType() != SHT_NULL)
                     sec->getShdr().serialize(file, ehdr->e_ident[EI_CLASS], ehdr->e_ident[EI_DATA]);
             }
         } else
            section->serialize(file, ehdr->e_ident[EI_CLASS], ehdr->e_ident[EI_DATA]);
     }
 }
 
 ElfSection::ElfSection(Elf_Shdr &s, std::ifstream *file, Elf *parent)
 : shdr(s),
-  link(shdr.sh_link == SHN_UNDEF ? NULL : parent->getSection(shdr.sh_link)),
-  next(NULL), previous(NULL), index(-1)
+  link(shdr.sh_link == SHN_UNDEF ? nullptr : parent->getSection(shdr.sh_link)),
+  next(nullptr), previous(nullptr), index(-1)
 {
-    if ((file == NULL) || (shdr.sh_type == SHT_NULL) || (shdr.sh_type == SHT_NOBITS))
-        data = NULL;
+    if ((file == nullptr) || (shdr.sh_type == SHT_NULL) || (shdr.sh_type == SHT_NOBITS))
+        data = nullptr;
     else {
         data = new char[shdr.sh_size];
         int pos = file->tellg();
         file->seekg(shdr.sh_offset);
         file->read(data, shdr.sh_size);
         file->seekg(pos);
     }
     if (shdr.sh_name == 0)
-        name = NULL;
+        name = nullptr;
     else {
         ElfStrtab_Section *strtab = (ElfStrtab_Section *) parent->getSection(-1);
-        // Special case (see elfgeneric.cpp): if strtab is NULL, the
+        // Special case (see elfgeneric.cpp): if strtab is nullptr, the
         // section being created is the strtab.
-        if (strtab == NULL)
+        if (strtab == nullptr)
             name = &data[shdr.sh_name];
         else
             name = strtab->getStr(shdr.sh_name);
     }
     // Only SHT_REL/SHT_RELA sections use sh_info to store a section
     // number.
     if ((shdr.sh_type == SHT_REL) || (shdr.sh_type == SHT_RELA))
-        info.section = shdr.sh_info ? parent->getSection(shdr.sh_info) : NULL;
+        info.section = shdr.sh_info ? parent->getSection(shdr.sh_info) : nullptr;
     else
         info.index = shdr.sh_info;
 }
 
 unsigned int ElfSection::getAddr()
 {
     if (shdr.sh_addr != (Elf32_Word)-1)
         return shdr.sh_addr;
 
     // It should be safe to adjust sh_addr for all allocated sections that
     // are neither SHT_NOBITS nor SHT_PROGBITS
-    if ((previous != NULL) && isRelocatable()) {
+    if ((previous != nullptr) && isRelocatable()) {
         unsigned int addr = previous->getAddr();
         if (previous->getType() != SHT_NOBITS)
             addr += previous->getSize();
 
         if (addr & (getAddrAlign() - 1))
             addr = (addr | (getAddrAlign() - 1)) + 1;
 
         return (shdr.sh_addr = addr);
@@ -493,17 +493,17 @@ unsigned int ElfSection::getAddr()
     return shdr.sh_addr;
 }
 
 unsigned int ElfSection::getOffset()
 {
     if (shdr.sh_offset != (Elf32_Word)-1)
         return shdr.sh_offset;
 
-    if (previous == NULL)
+    if (previous == nullptr)
         return (shdr.sh_offset = 0);
 
     unsigned int offset = previous->getOffset();
 
     ElfSegment *ptload = getSegmentByType(PT_LOAD);
     ElfSegment *prev_ptload = previous->getSegmentByType(PT_LOAD);
 
     if (ptload && (ptload == prev_ptload)) {
@@ -542,18 +542,18 @@ unsigned int ElfSection::getOffset()
 
 int ElfSection::getIndex()
 {
     if (index != -1)
         return index;
     if (getType() == SHT_NULL)
         return (index = 0);
     ElfSection *reference;
-    for (reference = previous; (reference != NULL) && (reference->getType() == SHT_NULL); reference = reference->getPrevious());
-    if (reference == NULL)
+    for (reference = previous; (reference != nullptr) && (reference->getType() == SHT_NULL); reference = reference->getPrevious());
+    if (reference == nullptr)
         return (index = 1);
     return (index = reference->getIndex() + 1);
 }
 
 Elf_Shdr &ElfSection::getShdr()
 {
     getOffset();
     if (shdr.sh_link == (Elf32_Word)-1)
@@ -656,23 +656,23 @@ void ElfSegment::clear()
 }
 
 ElfValue *ElfDynamic_Section::getValueForType(unsigned int tag)
 {
     for (unsigned int i = 0; i < shdr.sh_size / shdr.sh_entsize; i++)
         if (dyns[i].tag == tag)
             return dyns[i].value;
 
-    return NULL;
+    return nullptr;
 }
 
 ElfSection *ElfDynamic_Section::getSectionForType(unsigned int tag)
 {
     ElfValue *value = getValueForType(tag);
-    return value ? value->getSection() : NULL;
+    return value ? value->getSection() : nullptr;
 }
 
 bool ElfDynamic_Section::setValueForType(unsigned int tag, ElfValue *val)
 {
     unsigned int i;
     unsigned int shnum = shdr.sh_size / shdr.sh_entsize;
     for (i = 0; (i < shnum) && (dyns[i].tag != DT_NULL); i++)
         if (dyns[i].tag == tag) {
@@ -734,17 +734,17 @@ ElfDynamic_Section::ElfDynamic_Section(E
         case DT_FINI_ARRAY:
         case DT_GNU_HASH:
         case DT_VERSYM:
         case DT_VERNEED:
         case DT_VERDEF:
             dyns[i].value = new ElfLocation(dyn.d_un.d_ptr, parent);
             break;
         default:
-            dyns[i].value = NULL;
+            dyns[i].value = nullptr;
         }
     }
     // Another loop to get the section sizes
     for (unsigned int i = 0; i < s.sh_size / s.sh_entsize; i++)
         switch (dyns[i].tag) {
         case DT_PLTRELSZ:
             dyns[i].value = new ElfSize(getSectionForType(DT_JMPREL));
             break;
@@ -783,34 +783,34 @@ ElfDynamic_Section::~ElfDynamic_Section(
         delete dyns[i].value;
 }
 
 void ElfDynamic_Section::serialize(std::ofstream &file, char ei_class, char ei_data)
 {
     for (unsigned int i = 0; i < shdr.sh_size / shdr.sh_entsize; i++) {
         Elf_Dyn dyn;
         dyn.d_tag = dyns[i].tag;
-        dyn.d_un.d_val = (dyns[i].value != NULL) ? dyns[i].value->getValue() : 0;
+        dyn.d_un.d_val = (dyns[i].value != nullptr) ? dyns[i].value->getValue() : 0;
         dyn.serialize(file, ei_class, ei_data);
     }
 }
 
 ElfSymtab_Section::ElfSymtab_Section(Elf_Shdr &s, std::ifstream *file, Elf *parent)
 : ElfSection(s, file, parent)
 {
     int pos = file->tellg();
     syms.resize(s.sh_size / s.sh_entsize);
     ElfStrtab_Section *strtab = (ElfStrtab_Section *)getLink();
     file->seekg(shdr.sh_offset);
     for (unsigned int i = 0; i < shdr.sh_size / shdr.sh_entsize; i++) {
         Elf_Sym sym(*file, parent->getClass(), parent->getData());
         syms[i].name = strtab->getStr(sym.st_name);
         syms[i].info = sym.st_info;
         syms[i].other = sym.st_other;
-        ElfSection *section = (sym.st_shndx == SHN_ABS) ? NULL : parent->getSection(sym.st_shndx);
+        ElfSection *section = (sym.st_shndx == SHN_ABS) ? nullptr : parent->getSection(sym.st_shndx);
         new (&syms[i].value) ElfLocation(section, sym.st_value, ElfLocation::ABSOLUTE);
         syms[i].size = sym.st_size;
         syms[i].defined = (sym.st_shndx != SHN_UNDEF);
     }
     file->seekg(pos);
 }
 
 void
@@ -838,37 +838,37 @@ ElfSymtab_Section::lookup(const char *na
 {
     for (std::vector<Elf_SymValue>::iterator sym = syms.begin();
          sym != syms.end(); sym++) {
         if ((type_filter & (1 << ELF32_ST_TYPE(sym->info))) &&
             (strcmp(sym->name, name) == 0)) {
             return &*sym;
         }
     }
-    return NULL;
+    return nullptr;
 }
 
 const char *
 ElfStrtab_Section::getStr(unsigned int index)
 {
     for (std::vector<table_storage>::iterator t = table.begin();
          t != table.end(); t++) {
         if (index < t->used)
             return t->buf + index;
         index -= t->used;
     }
     assert(1 == 0);
-    return NULL;
+    return nullptr;
 }
 
 const char *
 ElfStrtab_Section::getStr(const char *string)
 {
-    if (string == NULL)
-        return NULL;
+    if (string == nullptr)
+        return nullptr;
 
     // If the given string is within the section, return it
     for (std::vector<table_storage>::iterator t = table.begin();
          t != table.end(); t++)
         if ((string >= t->buf) && (string < t->buf + t->used))
             return string;
 
     // TODO: should scan in the section to find an existing string
@@ -887,17 +887,17 @@ ElfStrtab_Section::getStr(const char *st
     markDirty();
 
     return alloc_str;
 }
 
 unsigned int
 ElfStrtab_Section::getStrIndex(const char *string)
 {
-    if (string == NULL)
+    if (string == nullptr)
         return 0;
 
     unsigned int index = 0;
     string = getStr(string);
     for (std::vector<table_storage>::iterator t = table.begin();
          t != table.end(); t++) {
         if ((string >= t->buf) && (string < t->buf + t->used))
             return index + (string - t->buf);
--- a/build/unix/elfhack/elfhack.cpp
+++ b/build/unix/elfhack/elfhack.cpp
@@ -21,17 +21,17 @@
 #endif
 #ifndef R_ARM_JUMP24
 #define R_ARM_JUMP24 0x1d
 #endif
 #ifndef R_ARM_THM_JUMP24
 #define R_ARM_THM_JUMP24 0x1e
 #endif
 
-char *rundir = NULL;
+char *rundir = nullptr;
 
 template <typename T>
 struct wrapped {
     T value;
 };
 
 class Elf_Addr_Traits {
 public:
@@ -58,17 +58,17 @@ public:
     }
 };
 
 typedef serializable<Elf_RelHack_Traits> Elf_RelHack;
 
 class ElfRelHack_Section: public ElfSection {
 public:
     ElfRelHack_Section(Elf_Shdr &s)
-    : ElfSection(s, NULL, NULL)
+    : ElfSection(s, nullptr, nullptr)
     {
         name = elfhack_data;
     };
 
     void serialize(std::ofstream &file, char ei_class, char ei_data)
     {
         for (std::vector<Elf_RelHack>::iterator i = rels.begin();
              i != rels.end(); ++i)
@@ -85,17 +85,17 @@ public:
     }
 private:
     std::vector<Elf_RelHack> rels;
 };
 
 class ElfRelHackCode_Section: public ElfSection {
 public:
     ElfRelHackCode_Section(Elf_Shdr &s, Elf &e, unsigned int init)
-    : ElfSection(s, NULL, NULL), parent(e), init(init) {
+    : ElfSection(s, nullptr, nullptr), parent(e), init(init) {
         std::string file(rundir);
         file += "/inject/";
         switch (parent.getMachine()) {
         case EM_386:
             file += "x86";
             break;
         case EM_X86_64:
             file += "x86_64";
@@ -109,25 +109,25 @@ public:
         file += ".o";
         std::ifstream inject(file.c_str(), std::ios::in|std::ios::binary);
         elf = new Elf(inject);
         if (elf->getType() != ET_REL)
             throw std::runtime_error("object for injected code is not ET_REL");
         if (elf->getMachine() != parent.getMachine())
             throw std::runtime_error("architecture of object for injected code doesn't match");
 
-        ElfSymtab_Section *symtab = NULL;
+        ElfSymtab_Section *symtab = nullptr;
 
         // Find the symbol table.
-        for (ElfSection *section = elf->getSection(1); section != NULL;
+        for (ElfSection *section = elf->getSection(1); section != nullptr;
              section = section->getNext()) {
             if (section->getType() == SHT_SYMTAB)
                 symtab = (ElfSymtab_Section *) section;
         }
-        if (symtab == NULL)
+        if (symtab == nullptr)
             throw std::runtime_error("Couldn't find a symbol table for the injected code");
 
         // Find the init symbol
         entry_point = -1;
         Elf_SymValue *sym = symtab->lookup(init ? "init" : "init_noinit");
         if (!sym)
             throw std::runtime_error("Couldn't find an 'init' symbol in the injected code");
 
@@ -166,17 +166,17 @@ public:
     void serialize(std::ofstream &file, char ei_class, char ei_data)
     {
         // Readjust code offsets
         for (std::vector<ElfSection *>::iterator c = code.begin(); c != code.end(); c++)
             (*c)->getShdr().sh_addr += getAddr();
 
         // Apply relocations
         for (std::vector<ElfSection *>::iterator c = code.begin(); c != code.end(); c++) {
-            for (ElfSection *rel = elf->getSection(1); rel != NULL; rel = rel->getNext())
+            for (ElfSection *rel = elf->getSection(1); rel != nullptr; rel = rel->getNext())
                 if (((rel->getType() == SHT_REL) ||
                      (rel->getType() == SHT_RELA)) &&
                     (rel->getInfo().section == *c)) {
                     if (rel->getType() == SHT_REL)
                         apply_relocations((ElfRel_Section<Elf_Rel> *)rel, *c);
                     else
                         apply_relocations((ElfRel_Section<Elf_Rela> *)rel, *c);
                 }
@@ -200,17 +200,17 @@ private:
             find_code(section);
         }
     }
 
     /* Look at the relocations associated to the given section to find other
      * sections that it requires */
     void find_code(ElfSection *section)
     {
-        for (ElfSection *s = elf->getSection(1); s != NULL;
+        for (ElfSection *s = elf->getSection(1); s != nullptr;
              s = s->getNext()) {
             if (((s->getType() == SHT_REL) ||
                  (s->getType() == SHT_RELA)) &&
                 (s->getInfo().section == section)) {
                 if (s->getType() == SHT_REL)
                     scan_relocs_for_code((ElfRel_Section<Elf_Rel> *)s);
                 else
                     scan_relocs_for_code((ElfRel_Section<Elf_Rela> *)s);
@@ -220,19 +220,19 @@ private:
 
     template <typename Rel_Type>
     void scan_relocs_for_code(ElfRel_Section<Rel_Type> *rel)
     {
         ElfSymtab_Section *symtab = (ElfSymtab_Section *)rel->getLink();
         for (auto r = rel->rels.begin(); r != rel->rels.end(); r++) {
             ElfSection *section = symtab->syms[ELF32_R_SYM(r->r_info)].value.getSection();
             if (section) {
-                for (ElfSection *s = elf->getSection(1); s != NULL; s = s->getNext()) {
+                for (ElfSection *s = elf->getSection(1); s != nullptr; s = s->getNext()) {
                     if (section == s)
-                        section = NULL;
+                        section = nullptr;
                         break;
                 }
             }
             add_code_section(section);
         }
     }
 
     class pc32_relocation {
@@ -341,17 +341,17 @@ private:
         assert(rel->getType() == Rel_Type::sh_type);
         char *buf = data + (the_code->getAddr() - code.front()->getAddr());
         // TODO: various checks on the sections
         ElfSymtab_Section *symtab = (ElfSymtab_Section *)rel->getLink();
         for (typename std::vector<Rel_Type>::iterator r = rel->rels.begin(); r != rel->rels.end(); r++) {
             // TODO: various checks on the symbol
             const char *name = symtab->syms[ELF32_R_SYM(r->r_info)].name;
             unsigned int addr;
-            if (symtab->syms[ELF32_R_SYM(r->r_info)].value.getSection() == NULL) {
+            if (symtab->syms[ELF32_R_SYM(r->r_info)].value.getSection() == nullptr) {
                 if (strcmp(name, "relhack") == 0) {
                     addr = getNext()->getAddr();
                 } else if (strcmp(name, "elf_header") == 0) {
                     // TODO: change this ungly hack to something better
                     ElfSection *ehdr = parent.getSection(1)->getPrevious()->getPrevious();
                     addr = ehdr->getAddr();
                 } else if (strcmp(name, "original_init") == 0) {
                     addr = init;
@@ -495,17 +495,17 @@ void maybe_split_segment(Elf *elf, ElfSe
         }
     }
 }
 
 template <typename Rel_Type>
 int do_relocation_section(Elf *elf, unsigned int rel_type, unsigned int rel_type2, bool force, bool fill)
 {
     ElfDynamic_Section *dyn = elf->getDynSection();
-    if (dyn ==NULL) {
+    if (dyn == nullptr) {
         fprintf(stderr, "Couldn't find SHT_DYNAMIC section\n");
         return -1;
     }
 
     ElfSegment *relro = elf->getSegmentByType(PT_GNU_RELRO);
 
     ElfRel_Section<Rel_Type> *section = (ElfRel_Section<Rel_Type> *)dyn->getSectionForType(Rel_Type::d_tag);
     assert(section->getType() == Rel_Type::sh_type);
@@ -530,17 +530,17 @@ int do_relocation_section(Elf *elf, unsi
     //   case, we interpose as well, by replacing the first entry in the
     //   array to point to the injected code, and have the injected code
     //   call the original first entry.
     // The binary may have .ctors instead of DT_INIT_ARRAY, for its init
     // functions, but this falls into the second case above, since .ctors
     // are actually run by DT_INIT code.
     ElfValue *value = dyn->getValueForType(DT_INIT);
     unsigned int original_init = value ? value->getValue() : 0;
-    ElfSection *init_array = NULL;
+    ElfSection *init_array = nullptr;
     if (!value || !value->getValue()) {
         value = dyn->getValueForType(DT_INIT_ARRAYSZ);
         if (value && value->getValue() >= entry_sz)
             init_array = dyn->getSectionForType(DT_INIT_ARRAY);
     }
 
     Elf_Shdr relhack_section(relhack32_section);
     Elf_Shdr relhackcode_section(relhackcode32_section);
@@ -557,19 +557,19 @@ int do_relocation_section(Elf *elf, unsi
          i != section->rels.end(); i++) {
         // We don't need to keep R_*_NONE relocations
         if (!ELF32_R_TYPE(i->r_info))
             continue;
         ElfLocation loc(i->r_offset, elf);
         // __cxa_pure_virtual is a function used in vtables to point at pure
         // virtual methods. The __cxa_pure_virtual function usually abort()s.
         // These functions are however normally never called. In the case
-        // where they would, jumping to the NULL address instead of calling
+        // where they would, jumping to the null address instead of calling
         // __cxa_pure_virtual is going to work just as well. So we can remove
-        // relocations for the __cxa_pure_virtual symbol and NULL out the
+        // relocations for the __cxa_pure_virtual symbol and null out the
         // content at the offset pointed by the relocation.
         if (sym) {
             if (sym->defined) {
                 // If we are statically linked to libstdc++, the
                 // __cxa_pure_virtual symbol is defined in our lib, and we
                 // have relative relocations (rel_type) for it.
                 if (ELF32_R_TYPE(i->r_info) == rel_type) {
                     Elf_Addr addr(loc.getBuffer(), entry_sz, elf->getClass(), elf->getData());
@@ -612,17 +612,17 @@ int do_relocation_section(Elf *elf, unsi
                     relhack->push_back(relhack_entry);
                 relhack_entry.r_offset = i->r_offset;
                 relhack_entry.r_info = 1;
             }
         }
     }
     if (relhack_entry.r_offset)
         relhack->push_back(relhack_entry);
-    // Last entry must be NULL
+    // Last entry must be nullptr
     relhack_entry.r_offset = relhack_entry.r_info = 0;
     relhack->push_back(relhack_entry);
 
     unsigned int old_end = section->getOffset() + section->getSize();
 
     if (init_array) {
         if (! init_array_reloc) {
             fprintf(stderr, "Didn't find relocation for DT_INIT_ARRAY's first entry. Skipping\n");
@@ -694,17 +694,17 @@ void do_file(const char *name, bool back
     Elf elf(file);
     unsigned int size = elf.getSize();
     fprintf(stderr, "%s: ", name);
     if (elf.getType() != ET_DYN) {
         fprintf(stderr, "Not a shared object. Skipping\n");
         return;
     }
 
-    for (ElfSection *section = elf.getSection(1); section != NULL;
+    for (ElfSection *section = elf.getSection(1); section != nullptr;
          section = section->getNext()) {
         if (section->getName() &&
             (strncmp(section->getName(), ".elfhack.", 9) == 0)) {
             fprintf(stderr, "Already elfhacked. Skipping\n");
             return;
         }
     }
 
@@ -739,18 +739,18 @@ void undo_file(const char *name, bool ba
     Elf elf(file);
     unsigned int size = elf.getSize();
     fprintf(stderr, "%s: ", name);
     if (elf.getType() != ET_DYN) {
         fprintf(stderr, "Not a shared object. Skipping\n");
         return;
     }
 
-    ElfSection *data = NULL, *text = NULL;
-    for (ElfSection *section = elf.getSection(1); section != NULL;
+    ElfSection *data = nullptr, *text = nullptr;
+    for (ElfSection *section = elf.getSection(1); section != nullptr;
          section = section->getNext()) {
         if (section->getName() &&
             (strcmp(section->getName(), elfhack_data) == 0))
             data = section;
         if (section->getName() &&
             (strcmp(section->getName(), elfhack_text) == 0))
             text = section;
     }
@@ -761,17 +761,17 @@ void undo_file(const char *name, bool ba
     }
     if (data != text->getNext()) {
         fprintf(stderr, elfhack_data " section not following " elfhack_text ". Skipping\n");
         return;
     }
 
     ElfSegment *first = elf.getSegmentByType(PT_LOAD);
     ElfSegment *second = elf.getSegmentByType(PT_LOAD, first);
-    ElfSegment *filler = NULL;
+    ElfSegment *filler = nullptr;
     // If the second PT_LOAD is a filler from elfhack --fill, check the third.
     if (!second->isElfHackFillerSegment()) {
         filler = second;
         second = elf.getSegmentByType(PT_LOAD, filler);
     }
     if (second->getFlags() != first->getFlags()) {
         fprintf(stderr, "Couldn't identify elfhacked PT_LOAD segments. Skipping\n");
         return;
@@ -798,17 +798,17 @@ void undo_file(const char *name, bool ba
 int main(int argc, char *argv[])
 {
     int arg;
     bool backup = false;
     bool force = false;
     bool revert = false;
     bool fill = false;
     char *lastSlash = rindex(argv[0], '/');
-    if (lastSlash != NULL)
+    if (lastSlash != nullptr)
         rundir = strndup(argv[0], lastSlash - argv[0]);
     for (arg = 1; arg < argc; arg++) {
         if (strcmp(argv[arg], "-f") == 0)
             force = true;
         else if (strcmp(argv[arg], "-b") == 0)
             backup = true;
         else if (strcmp(argv[arg], "-r") == 0)
             revert = true;
--- a/build/unix/elfhack/elfxx.h
+++ b/build/unix/elfhack/elfxx.h
@@ -1,12 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "mozilla/NullPtr.h"
+
 #include <stdexcept>
 #include <list>
 #include <vector>
 #include <cstring>
 #include <iostream>
 #include <fstream>
 #include <algorithm>
 #include <elf.h>
@@ -110,32 +112,32 @@ public:
 
     template <class endian, typename R, typename T>
     static void swap(T &t, R &r);
 };
 
 class ElfValue {
 public:
     virtual unsigned int getValue() { return 0; }
-    virtual ElfSection *getSection() { return NULL; }
+    virtual ElfSection *getSection() { return nullptr; }
 };
 
 class ElfPlainValue: public ElfValue {
     unsigned int value;
 public:
     ElfPlainValue(unsigned int val): value(val) {};
     unsigned int getValue() { return value; }
 };
 
 class ElfLocation: public ElfValue {
     ElfSection *section;
     unsigned int offset;
 public:
     enum position { ABSOLUTE, RELATIVE };
-    ElfLocation(): section(NULL), offset(0) {};
+    ElfLocation(): section(nullptr), offset(0) {};
     ElfLocation(ElfSection *section, unsigned int off, enum position pos = RELATIVE);
     ElfLocation(unsigned int location, Elf *elf);
     unsigned int getValue();
     ElfSection *getSection() { return section; }
     const char *getBuffer();
 };
 
 class ElfSize: public ElfValue {
@@ -265,17 +267,17 @@ public:
     Elf(std::ifstream &file);
     ~Elf();
 
     /* index == -1 is treated as index == ehdr.e_shstrndx */
     ElfSection *getSection(int index);
 
     ElfSection *getSectionAt(unsigned int offset);
 
-    ElfSegment *getSegmentByType(unsigned int type, ElfSegment *last = NULL);
+    ElfSegment *getSegmentByType(unsigned int type, ElfSegment *last = nullptr);
 
     ElfDynamic_Section *getDynSection();
 
     void normalize();
     void write(std::ofstream &file);
 
     char getClass();
     char getData();
@@ -350,53 +352,53 @@ public:
                 (getType() == SHT_GNU_verdef) ||
                 (getType() == SHT_GNU_verneed) ||
                 (getType() == SHT_GNU_versym) ||
                 getSegmentByType(PT_INTERP)) &&
                 (getFlags() & SHF_ALLOC);
     }
 
     void insertAfter(ElfSection *section, bool dirty = true) {
-        if (previous != NULL)
+        if (previous != nullptr)
             previous->next = next;
-        if (next != NULL)
+        if (next != nullptr)
             next->previous = previous;
         previous = section;
-        if (section != NULL) {
+        if (section != nullptr) {
             next = section->next;
             section->next = this;
         } else
-            next = NULL;
-        if (next != NULL)
+            next = nullptr;
+        if (next != nullptr)
             next->previous = this;
         if (dirty)
             markDirty();
         insertInSegments(section->segments);
     }
 
     void insertBefore(ElfSection *section, bool dirty = true) {
-        if (previous != NULL)
+        if (previous != nullptr)
             previous->next = next;
-        if (next != NULL)
+        if (next != nullptr)
             next->previous = previous;
         next = section;
-        if (section != NULL) {
+        if (section != nullptr) {
             previous = section->previous;
             section->previous = this;
         } else
-            previous = NULL;
-        if (previous != NULL)
+            previous = nullptr;
+        if (previous != nullptr)
             previous->next = this;
         if (dirty)
             markDirty();
         insertInSegments(section->segments);
     }
 
     void markDirty() {
-        if (link != NULL)
+        if (link != nullptr)
             shdr.sh_link = -1;
         if (info.index)
             shdr.sh_info = -1;
         shdr.sh_offset = -1;
         if (isRelocatable())
             shdr.sh_addr = -1;
         if (next)
             next->markDirty();
@@ -441,17 +443,17 @@ private:
 class ElfSegment {
 public:
     ElfSegment(Elf_Phdr *phdr);
 
     unsigned int getType() { return type; }
     unsigned int getFlags() { return flags; }
     unsigned int getAlign() { return align; }
 
-    ElfSection *getFirstSection() { return sections.empty() ? NULL : sections.front(); }
+    ElfSection *getFirstSection() { return sections.empty() ? nullptr : sections.front(); }
     int getVPDiff() { return v_p_diff; }
     unsigned int getFileSize();
     unsigned int getMemSize();
     unsigned int getOffset();
     unsigned int getAddr();
 
     void addSection(ElfSection *section);
     void removeSection(ElfSection *section);
@@ -649,25 +651,25 @@ inline char Elf::getType() {
 
 inline char Elf::getMachine() {
     return ehdr->e_machine;
 }
 
 inline unsigned int Elf::getSize() {
     ElfSection *section;
     for (section = shdr_section /* It's usually not far from the end */;
-        section->getNext() != NULL; section = section->getNext());
+        section->getNext() != nullptr; section = section->getNext());
     return section->getOffset() + section->getSize();
 }
 
 inline ElfSegment *ElfSection::getSegmentByType(unsigned int type) {
     for (std::vector<ElfSegment *>::iterator seg = segments.begin(); seg != segments.end(); seg++)
         if ((*seg)->getType() == type)
             return *seg;
-    return NULL;
+    return nullptr;
 }
 
 inline void ElfSection::insertInSegments(std::vector<ElfSegment *> &segs) {
     for (std::vector<ElfSegment *>::iterator it = segs.begin(); it != segs.end(); ++it) {
         (*it)->addSection(this);
     }
 }
 
@@ -684,17 +686,17 @@ inline ElfLocation::ElfLocation(unsigned
     offset = location - (section ? section->getAddr() : 0);
 }
 
 inline unsigned int ElfLocation::getValue() {
     return (section ? section->getAddr() : 0) + offset;
 }
 
 inline const char *ElfLocation::getBuffer() {
-    return section ? section->getData() + offset : NULL;
+    return section ? section->getData() + offset : nullptr;
 }
 
 inline unsigned int ElfSize::getValue() {
     return section->getSize();
 }
 
 inline unsigned int ElfEntSize::getValue() {
     return section->getEntSize();
--- a/build/win32/crashinject.cpp
+++ b/build/win32/crashinject.cpp
@@ -22,69 +22,70 @@ int main(int argc, char** argv)
   int pid = atoi(argv[1]);
   if (pid <= 0) {
     fprintf(stderr, "Usage: crashinject <PID>\n");
     return 1;
   }
 
   // find our DLL to inject
   wchar_t filename[_MAX_PATH];
-  if (GetModuleFileNameW(NULL, filename, sizeof(filename) / sizeof(wchar_t)) == 0)
+  if (GetModuleFileNameW(nullptr, filename,
+                         sizeof(filename) / sizeof(wchar_t)) == 0)
     return 1;
 
   wchar_t* slash = wcsrchr(filename, L'\\');
-  if (slash == NULL)
+  if (slash == nullptr)
     return 1;
 
   slash++;
   wcscpy(slash, L"crashinjectdll.dll");
 
   // now find our target process
   HANDLE targetProc = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION,
                                   FALSE,
                                   pid);
-  if (targetProc == NULL) {
+  if (targetProc == nullptr) {
     fprintf(stderr, "Error %d opening target process\n", GetLastError());
     return 1;
   }
 
   /*
    * This is sort of insane, but we're implementing a technique described here:
    * http://www.codeproject.com/KB/threads/winspy.aspx#section_2
    *
    * The gist is to use CreateRemoteThread to create a thread in the other
    * process, but cheat and make the thread function kernel32!LoadLibrary,
    * so that the only remote data we have to pass to the other process
    * is the path to the library we want to load. The library we're loading
    * will then do its dirty work inside the other process.
    */
   HMODULE hKernel32 = GetModuleHandleW(L"Kernel32");
   // allocate some memory to hold the path in the remote process
-  void*   pLibRemote = VirtualAllocEx(targetProc, NULL, sizeof(filename),
+  void*   pLibRemote = VirtualAllocEx(targetProc, nullptr, sizeof(filename),
                                       MEM_COMMIT, PAGE_READWRITE);
-  if (pLibRemote == NULL) {
+  if (pLibRemote == nullptr) {
     fprintf(stderr, "Error %d in VirtualAllocEx\n", GetLastError());
     CloseHandle(targetProc);
     return 1;
   }
 
   if (!WriteProcessMemory(targetProc, pLibRemote, (void*)filename,
-                          sizeof(filename), NULL)) {
+                          sizeof(filename), nullptr)) {
     fprintf(stderr, "Error %d in WriteProcessMemory\n", GetLastError());
     VirtualFreeEx(targetProc, pLibRemote, sizeof(filename), MEM_RELEASE);
     CloseHandle(targetProc);
     return 1;
   }
   // Now create a thread in the target process that will load our DLL
   HANDLE hThread = CreateRemoteThread(
-                     targetProc, NULL, 0,
+                     targetProc, nullptr, 0,
                      (LPTHREAD_START_ROUTINE)GetProcAddress(hKernel32,
                                                             "LoadLibraryW"),
-                     pLibRemote, 0, NULL);
-  if (hThread == NULL) {
+                     pLibRemote, 0, nullptr);
+  if (hThread == nullptr) {
     fprintf(stderr, "Error %d in CreateRemoteThread\n", GetLastError());
     VirtualFreeEx(targetProc, pLibRemote, sizeof(filename), MEM_RELEASE);
     CloseHandle(targetProc);
     return 1;
   }
   WaitForSingleObject(hThread, INFINITE);
   // Cleanup, not that it's going to matter at this point
   CloseHandle(hThread);
--- a/build/win32/crashinjectdll/crashinjectdll.cpp
+++ b/build/win32/crashinjectdll/crashinjectdll.cpp
@@ -23,16 +23,16 @@ BOOL WINAPI DllMain(
   DWORD dwReason,
   LPVOID lpvReserved
 )
 {
   if (tid == -1)
     // we have to crash on another thread because LoadLibrary() will
     // catch memory access errors and return failure to the calling process
     CreateThread(
-                 NULL,                   // default security attributes
+                 nullptr,                // default security attributes
                  0,                      // use default stack size
-                 CrashingThread  ,       // thread function name
-                 NULL,                   // argument to thread function
+                 CrashingThread,         // thread function name
+                 nullptr,                // argument to thread function
                  0,                      // use default creation flags
                  &tid);                  // returns the thread identifier
   return TRUE;
 }
--- a/mozglue/build/arm.cpp
+++ b/mozglue/build/arm.cpp
@@ -1,14 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* compile-time and runtime tests for whether to use various ARM extensions */
 
+#include "mozilla/NullPtr.h"
+
 #include "arm.h"
 
 #if defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
 namespace {
 
 // arm.h has parallel #ifs which declare MOZILLA_ARM_HAVE_CPUID_DETECTION.
 // We don't check it here so that we get compile errors if it's defined, but
 // we don't compile one of these detection methods. The detection code here is