• R/O
  • HTTP
  • SSH
  • HTTPS

mingw-get: Commit

The MinGW.org Installation Manager Tool


Commit MetaInfo

Revisiónf32b58680a31700042edfdc2703258f2273dfee5 (tree)
Tiempo2020-06-23 06:11:25
AutorKeith Marshall <keith@user...>
CommiterKeith Marshall

Log Message

Do not dereference nullptr in package directory trees.

Cambiar Resumen

Diferencia incremental

--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
11 2020-06-22 Keith Marshall <keith@users.osdn.me>
22
3+ Do not dereference nullptr in package directory trees.
4+
5+ * src/pkglist.h (pkgDirectory::Insert, pkgDirectory::InOrder):
6+ Delegate them to static class methods, with inline wrappers passing
7+ "this" pointer explicitly, thus obviating any need for...
8+ [this != NULL]: ...this invalid comparison.
9+
10+ * src/pkgshow.cpp (pkgDirectory::Insert, pkgDirectory::InOrder):
11+ Modify them, reimplementing as the requisite static class methods.
12+ (pkgDirectoryViewer::Dispatch): Reorganize process flow.
13+
14+2020-06-22 Keith Marshall <keith@users.osdn.me>
15+
316 Ignore spin wait requests with no designated referrer.
417
518 * src/pkgstat.h (pkgSpinWait::UpdateIndex) [this]: Cannot test for
--- a/src/pkglist.h
+++ b/src/pkglist.h
@@ -1,11 +1,10 @@
1-#ifndef PKGLIST_H
21 /*
32 * pkglist.h
43 *
54 * $Id$
65 *
7- * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
8- * Copyright (C) 2010, 2012, MinGW Project
6+ * Written by Keith Marshall <keith@users.osdn.me>
7+ * Copyright (C) 2010, 2012, 2020, MinGW.org Project
98 *
109 *
1110 * Declarations of the classes used to implement the package list
@@ -26,6 +25,7 @@
2625 * arising from the use of this software.
2726 *
2827 */
28+#ifndef PKGLIST_H
2929 #define PKGLIST_H 1
3030
3131 class pkgDirectory;
@@ -86,10 +86,15 @@ class pkgDirectory
8686 * binary tree, such that an in-order traversal will produce
8787 * an alpha-numerically sorted package list.
8888 */
89+ private:
90+ static void InOrder( pkgDirectory *, pkgDirectoryViewerEngine * );
91+ static pkgDirectory *Insert( pkgDirectory *, const char *, pkgDirectory * );
8992 public:
9093 pkgDirectory( pkgXmlNode * );
91- pkgDirectory *Insert( const char *, pkgDirectory * );
92- void InOrder( pkgDirectoryViewerEngine * );
94+ inline pkgDirectory *Insert( const char *key, pkgDirectory *entry )
95+ { return Insert( this, key, entry ); }
96+ inline void InOrder( pkgDirectoryViewerEngine *form )
97+ { InOrder( this, form ); }
9398 ~pkgDirectory();
9499
95100 protected:
--- a/src/pkgshow.cpp
+++ b/src/pkgshow.cpp
@@ -3,8 +3,8 @@
33 *
44 * $Id$
55 *
6- * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
7- * Copyright (C) 2009, 2010, 2012, MinGW Project
6+ * Written by Keith Marshall <keith@users.osdn.me>
7+ * Copyright (C) 2009, 2010, 2012, 2020, MinGW Project
88 *
99 *
1010 * Implementation of the classes and methods required to support the
@@ -439,19 +439,20 @@ pkgNroffLayoutEngine::WriteLn( int style, int offset, int maxlen )
439439 pkgDirectory::pkgDirectory( pkgXmlNode *item ):
440440 entry( item ), prev( NULL ), next( NULL ){}
441441
442-pkgDirectory *pkgDirectory::Insert( const char *keytype, pkgDirectory *newentry )
442+pkgDirectory *pkgDirectory::Insert
443+( pkgDirectory *dir, const char *keytype, pkgDirectory *newentry )
443444 {
444445 /* Add a new package or component reference to a directory compilation,
445446 * using an unbalanced binary tree representation to achieve a sorted
446447 * listing, in ascending alpha-numeric collating order.
447448 */
448- if( this && newentry )
449+ if( dir && newentry )
449450 {
450451 /* We have an existing directory to augment, and a valid reference
451452 * pointer for a new directory entry; we must locate the appropriate
452453 * insertion point, to achieve correct sort order.
453454 */
454- pkgDirectory *refpt, *pt = this;
455+ pkgDirectory *refpt, *pt = dir;
455456 const char *mt = "", *ref = newentry->entry->GetPropVal( keytype, mt );
456457 do { refpt = pt;
457458 if( pt->prev && strcmp( ref, pt->prev->entry->GetPropVal( keytype, mt )) < 0 )
@@ -522,32 +523,32 @@ pkgDirectory *pkgDirectory::Insert( const char *keytype, pkgDirectory *newentry
522523 * directory tree, or if that had never been previously assigned, then the
523524 * new entry, which will become the root of a new directory tree.
524525 */
525- return this ? this : newentry;
526+ return dir ? dir : newentry;
526527 }
527528
528-void pkgDirectory::InOrder( pkgDirectoryViewerEngine *action )
529+void pkgDirectory::InOrder
530+( pkgDirectory *dir, pkgDirectoryViewerEngine *action )
529531 {
530532 /* Perform an in-order traversal of a package directory tree,
531533 * invoking a specified processing action on each node in turn;
532534 * note that this requires a pointer to a concrete instance of
533535 * a "Viewer" class, derived from the abstract "ViewerEngine".
534536 */
535- if( this )
536- {
537- /* Proceeding only when we have a valid directory object,
537+ if( dir )
538+ { /* Proceeding only when we have a valid directory object,
538539 * recursively traverse the "left hand" (prev) sub-tree...
539540 */
540- prev->InOrder( action );
541+ InOrder( dir->prev, action );
541542 /*
542543 * ...processing the current node when no unprocessed
543544 * "left hand" sub-tree nodes remain...
544545 */
545- action->Dispatch( entry );
546+ action->Dispatch( dir->entry );
546547 /*
547548 * ...then finish off with a recursive traversal of the
548549 * "right-hand" (next) sub-tree...
549550 */
550- next->InOrder( action );
551+ InOrder( dir->next, action );
551552 }
552553 }
553554
@@ -800,24 +801,25 @@ void pkgDirectoryViewer::Dispatch( pkgXmlNode *entry )
800801 */
801802 if( entry->IsElementOfType( package_key ) )
802803 {
803- /* The selected entity is a full package;
804- * create an auxiliary directory...
805- */
806- pkgDirectory *dir = EnumerateComponents( entry );
807-
808- /* Signalling that a component list is to be included...
804+ /* The selected entity is a full package; signalling that a
805+ * component list is to be included, print the standard form
806+ * package name header...
809807 */
810808 ct = 0;
811- /* ...print the standard form package name header...
812- */
813809 EmitHeader( entry );
810+
811+ /* ...then compile an auxiliary directory, in which we may
812+ * enumerate the components of the package...
813+ */
814+ pkgDirectory *dir = EnumerateComponents( entry );
814815 if( dir != NULL )
815816 {
816- /* ...with included enumeration of the component names...
817+ /* ...to be printed in alphanumerically sorted order of
818+ * component names...
817819 */
818820 dir->InOrder( this ); putchar( '\n' );
819- /*
820- * ...before discarding the auxiliary directory.
821+
822+ /* ...before discarding the auxiliary directory.
821823 */
822824 delete dir;
823825 }
Show on old repository browser