OSDN Git Service

Do not dereference nullptr in package directory trees.
authorKeith Marshall <keith@users.osdn.me>
Mon, 22 Jun 2020 21:11:25 +0000 (22:11 +0100)
committerKeith Marshall <keith@users.osdn.me>
Mon, 22 Jun 2020 21:11:25 +0000 (22:11 +0100)
ChangeLog
src/pkglist.h
src/pkgshow.cpp

index 4bf3af3..f52a34d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2020-06-22  Keith Marshall  <keith@users.osdn.me>
 
 2020-06-22  Keith Marshall  <keith@users.osdn.me>
 
+       Do not dereference nullptr in package directory trees.
+
+       * src/pkglist.h (pkgDirectory::Insert, pkgDirectory::InOrder):
+       Delegate them to static class methods, with inline wrappers passing
+       "this" pointer explicitly, thus obviating any need for...
+       [this != NULL]: ...this invalid comparison.
+
+       * src/pkgshow.cpp (pkgDirectory::Insert, pkgDirectory::InOrder):
+       Modify them, reimplementing as the requisite static class methods.
+       (pkgDirectoryViewer::Dispatch): Reorganize process flow.
+
+2020-06-22  Keith Marshall  <keith@users.osdn.me>
+
        Ignore spin wait requests with no designated referrer.
 
        * src/pkgstat.h (pkgSpinWait::UpdateIndex) [this]: Cannot test for
        Ignore spin wait requests with no designated referrer.
 
        * src/pkgstat.h (pkgSpinWait::UpdateIndex) [this]: Cannot test for
index 64c845c..6e7ca2b 100644 (file)
@@ -1,11 +1,10 @@
-#ifndef PKGLIST_H
 /*
  * pkglist.h
  *
  * $Id$
  *
 /*
  * pkglist.h
  *
  * $Id$
  *
- * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
- * Copyright (C) 2010, 2012, MinGW Project
+ * Written by Keith Marshall <keith@users.osdn.me>
+ * Copyright (C) 2010, 2012, 2020, MinGW.org Project
  *
  *
  * Declarations of the classes used to implement the package list
  *
  *
  * Declarations of the classes used to implement the package list
@@ -26,6 +25,7 @@
  * arising from the use of this software.
  *
  */
  * arising from the use of this software.
  *
  */
+#ifndef PKGLIST_H
 #define PKGLIST_H  1
 
 class pkgDirectory;
 #define PKGLIST_H  1
 
 class pkgDirectory;
@@ -86,10 +86,15 @@ class pkgDirectory
    * binary tree, such that an in-order traversal will produce
    * an alpha-numerically sorted package list.
    */
    * binary tree, such that an in-order traversal will produce
    * an alpha-numerically sorted package list.
    */
+  private:
+    static void InOrder( pkgDirectory *, pkgDirectoryViewerEngine * );
+    static pkgDirectory *Insert( pkgDirectory *, const char *, pkgDirectory * );
   public:
     pkgDirectory( pkgXmlNode * );
   public:
     pkgDirectory( pkgXmlNode * );
-    pkgDirectory *Insert( const char *, pkgDirectory * );
-    void InOrder( pkgDirectoryViewerEngine * );
+    inline pkgDirectory *Insert( const char *key, pkgDirectory *entry )
+    { return Insert( this, key, entry ); }
+    inline void InOrder( pkgDirectoryViewerEngine *form )
+    { InOrder( this, form ); }
     ~pkgDirectory();
 
   protected:
     ~pkgDirectory();
 
   protected:
index a3eefdd..cdc17d3 100644 (file)
@@ -3,8 +3,8 @@
  *
  * $Id$
  *
  *
  * $Id$
  *
- * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
- * Copyright (C) 2009, 2010, 2012, MinGW Project
+ * Written by Keith Marshall <keith@users.osdn.me>
+ * Copyright (C) 2009, 2010, 2012, 2020, MinGW Project
  *
  *
  * Implementation of the classes and methods required to support the
  *
  *
  * Implementation of the classes and methods required to support the
@@ -439,19 +439,20 @@ pkgNroffLayoutEngine::WriteLn( int style, int offset, int maxlen )
 pkgDirectory::pkgDirectory( pkgXmlNode *item ):
 entry( item ), prev( NULL ), next( NULL ){}
 
 pkgDirectory::pkgDirectory( pkgXmlNode *item ):
 entry( item ), prev( NULL ), next( NULL ){}
 
-pkgDirectory *pkgDirectory::Insert( const char *keytype, pkgDirectory *newentry )
+pkgDirectory *pkgDirectory::Insert
+( pkgDirectory *dir, const char *keytype, pkgDirectory *newentry )
 {
   /* Add a new package or component reference to a directory compilation,
    * using an unbalanced binary tree representation to achieve a sorted
    * listing, in ascending alpha-numeric collating order.
    */
 {
   /* Add a new package or component reference to a directory compilation,
    * using an unbalanced binary tree representation to achieve a sorted
    * listing, in ascending alpha-numeric collating order.
    */
-  if( this && newentry )
+  if( dir && newentry )
   {
     /* We have an existing directory to augment, and a valid reference
      * pointer for a new directory entry; we must locate the appropriate
      * insertion point, to achieve correct sort order.
      */
   {
     /* We have an existing directory to augment, and a valid reference
      * pointer for a new directory entry; we must locate the appropriate
      * insertion point, to achieve correct sort order.
      */
-    pkgDirectory *refpt, *pt = this;
+    pkgDirectory *refpt, *pt = dir;
     const char *mt = "", *ref = newentry->entry->GetPropVal( keytype, mt );
     do { refpt = pt;
         if( pt->prev && strcmp( ref, pt->prev->entry->GetPropVal( keytype, mt )) < 0 )
     const char *mt = "", *ref = newentry->entry->GetPropVal( keytype, mt );
     do { refpt = pt;
         if( pt->prev && strcmp( ref, pt->prev->entry->GetPropVal( keytype, mt )) < 0 )
@@ -522,32 +523,32 @@ pkgDirectory *pkgDirectory::Insert( const char *keytype, pkgDirectory *newentry
    * directory tree, or if that had never been previously assigned, then the
    * new entry, which will become the root of a new directory tree.
    */
    * directory tree, or if that had never been previously assigned, then the
    * new entry, which will become the root of a new directory tree.
    */
-  return this ? this : newentry;
+  return dir ? dir : newentry;
 }
 
 }
 
-void pkgDirectory::InOrder( pkgDirectoryViewerEngine *action )
+void pkgDirectory::InOrder
+( pkgDirectory *dir, pkgDirectoryViewerEngine *action )
 {
   /* Perform an in-order traversal of a package directory tree,
    * invoking a specified processing action on each node in turn;
    * note that this requires a pointer to a concrete instance of
    * a "Viewer" class, derived from the abstract "ViewerEngine".
    */
 {
   /* Perform an in-order traversal of a package directory tree,
    * invoking a specified processing action on each node in turn;
    * note that this requires a pointer to a concrete instance of
    * a "Viewer" class, derived from the abstract "ViewerEngine".
    */
-  if( this )
-  {
-    /* Proceeding only when we have a valid directory object,
+  if( dir )
+  { /* Proceeding only when we have a valid directory object,
      * recursively traverse the "left hand" (prev) sub-tree...
      */
      * recursively traverse the "left hand" (prev) sub-tree...
      */
-    prev->InOrder( action );
+    InOrder( dir->prev, action );
     /*
      * ...processing the current node when no unprocessed
      * "left hand" sub-tree nodes remain...
      */
     /*
      * ...processing the current node when no unprocessed
      * "left hand" sub-tree nodes remain...
      */
-    action->Dispatch( entry );
+    action->Dispatch( dir->entry );
     /*
      * ...then finish off with a recursive traversal of the
      * "right-hand" (next) sub-tree...
      */
     /*
      * ...then finish off with a recursive traversal of the
      * "right-hand" (next) sub-tree...
      */
-    next->InOrder( action );
+    InOrder( dir->next, action );
   }
 }
 
   }
 }
 
@@ -800,24 +801,25 @@ void pkgDirectoryViewer::Dispatch( pkgXmlNode *entry )
    */
   if( entry->IsElementOfType( package_key ) )
   {
    */
   if( entry->IsElementOfType( package_key ) )
   {
-    /* The selected entity is a full package;
-     * create an auxiliary directory...
-     */
-    pkgDirectory *dir = EnumerateComponents( entry );
-
-    /* Signalling that a component list is to be included...
+    /* The selected entity is a full package; signalling that a
+     * component list is to be included, print the standard form
+     * package name header...
      */
     ct = 0;
      */
     ct = 0;
-    /* ...print the standard form package name header...
-     */
     EmitHeader( entry );
     EmitHeader( entry );
+
+    /* ...then compile an auxiliary directory, in which we may
+     * enumerate the components of the package...
+     */
+    pkgDirectory *dir = EnumerateComponents( entry );
     if( dir != NULL )
     {
     if( dir != NULL )
     {
-      /* ...with included enumeration of the component names...
+      /* ...to be printed in alphanumerically sorted order of
+       * component names...
        */
       dir->InOrder( this ); putchar( '\n' );
        */
       dir->InOrder( this ); putchar( '\n' );
-      /*
-       * ...before discarding the auxiliary directory.
+
+      /* ...before discarding the auxiliary directory.
        */
       delete dir;
     }
        */
       delete dir;
     }