修訂 | f32b58680a31700042edfdc2703258f2273dfee5 (tree) |
---|---|
時間 | 2020-06-23 06:11:25 |
作者 | ![]() |
Commiter | Keith Marshall |
Do not dereference nullptr in package directory trees.
@@ -1,5 +1,18 @@ | ||
1 | 1 | 2020-06-22 Keith Marshall <keith@users.osdn.me> |
2 | 2 | |
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 | + | |
3 | 16 | Ignore spin wait requests with no designated referrer. |
4 | 17 | |
5 | 18 | * src/pkgstat.h (pkgSpinWait::UpdateIndex) [this]: Cannot test for |
@@ -1,11 +1,10 @@ | ||
1 | -#ifndef PKGLIST_H | |
2 | 1 | /* |
3 | 2 | * pkglist.h |
4 | 3 | * |
5 | 4 | * $Id$ |
6 | 5 | * |
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 | |
9 | 8 | * |
10 | 9 | * |
11 | 10 | * Declarations of the classes used to implement the package list |
@@ -26,6 +25,7 @@ | ||
26 | 25 | * arising from the use of this software. |
27 | 26 | * |
28 | 27 | */ |
28 | +#ifndef PKGLIST_H | |
29 | 29 | #define PKGLIST_H 1 |
30 | 30 | |
31 | 31 | class pkgDirectory; |
@@ -86,10 +86,15 @@ class pkgDirectory | ||
86 | 86 | * binary tree, such that an in-order traversal will produce |
87 | 87 | * an alpha-numerically sorted package list. |
88 | 88 | */ |
89 | + private: | |
90 | + static void InOrder( pkgDirectory *, pkgDirectoryViewerEngine * ); | |
91 | + static pkgDirectory *Insert( pkgDirectory *, const char *, pkgDirectory * ); | |
89 | 92 | public: |
90 | 93 | 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 ); } | |
93 | 98 | ~pkgDirectory(); |
94 | 99 | |
95 | 100 | protected: |
@@ -3,8 +3,8 @@ | ||
3 | 3 | * |
4 | 4 | * $Id$ |
5 | 5 | * |
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 | |
8 | 8 | * |
9 | 9 | * |
10 | 10 | * Implementation of the classes and methods required to support the |
@@ -439,19 +439,20 @@ pkgNroffLayoutEngine::WriteLn( int style, int offset, int maxlen ) | ||
439 | 439 | pkgDirectory::pkgDirectory( pkgXmlNode *item ): |
440 | 440 | entry( item ), prev( NULL ), next( NULL ){} |
441 | 441 | |
442 | -pkgDirectory *pkgDirectory::Insert( const char *keytype, pkgDirectory *newentry ) | |
442 | +pkgDirectory *pkgDirectory::Insert | |
443 | +( pkgDirectory *dir, const char *keytype, pkgDirectory *newentry ) | |
443 | 444 | { |
444 | 445 | /* Add a new package or component reference to a directory compilation, |
445 | 446 | * using an unbalanced binary tree representation to achieve a sorted |
446 | 447 | * listing, in ascending alpha-numeric collating order. |
447 | 448 | */ |
448 | - if( this && newentry ) | |
449 | + if( dir && newentry ) | |
449 | 450 | { |
450 | 451 | /* We have an existing directory to augment, and a valid reference |
451 | 452 | * pointer for a new directory entry; we must locate the appropriate |
452 | 453 | * insertion point, to achieve correct sort order. |
453 | 454 | */ |
454 | - pkgDirectory *refpt, *pt = this; | |
455 | + pkgDirectory *refpt, *pt = dir; | |
455 | 456 | const char *mt = "", *ref = newentry->entry->GetPropVal( keytype, mt ); |
456 | 457 | do { refpt = pt; |
457 | 458 | if( pt->prev && strcmp( ref, pt->prev->entry->GetPropVal( keytype, mt )) < 0 ) |
@@ -522,32 +523,32 @@ pkgDirectory *pkgDirectory::Insert( const char *keytype, pkgDirectory *newentry | ||
522 | 523 | * directory tree, or if that had never been previously assigned, then the |
523 | 524 | * new entry, which will become the root of a new directory tree. |
524 | 525 | */ |
525 | - return this ? this : newentry; | |
526 | + return dir ? dir : newentry; | |
526 | 527 | } |
527 | 528 | |
528 | -void pkgDirectory::InOrder( pkgDirectoryViewerEngine *action ) | |
529 | +void pkgDirectory::InOrder | |
530 | +( pkgDirectory *dir, pkgDirectoryViewerEngine *action ) | |
529 | 531 | { |
530 | 532 | /* Perform an in-order traversal of a package directory tree, |
531 | 533 | * invoking a specified processing action on each node in turn; |
532 | 534 | * note that this requires a pointer to a concrete instance of |
533 | 535 | * a "Viewer" class, derived from the abstract "ViewerEngine". |
534 | 536 | */ |
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, | |
538 | 539 | * recursively traverse the "left hand" (prev) sub-tree... |
539 | 540 | */ |
540 | - prev->InOrder( action ); | |
541 | + InOrder( dir->prev, action ); | |
541 | 542 | /* |
542 | 543 | * ...processing the current node when no unprocessed |
543 | 544 | * "left hand" sub-tree nodes remain... |
544 | 545 | */ |
545 | - action->Dispatch( entry ); | |
546 | + action->Dispatch( dir->entry ); | |
546 | 547 | /* |
547 | 548 | * ...then finish off with a recursive traversal of the |
548 | 549 | * "right-hand" (next) sub-tree... |
549 | 550 | */ |
550 | - next->InOrder( action ); | |
551 | + InOrder( dir->next, action ); | |
551 | 552 | } |
552 | 553 | } |
553 | 554 |
@@ -800,24 +801,25 @@ void pkgDirectoryViewer::Dispatch( pkgXmlNode *entry ) | ||
800 | 801 | */ |
801 | 802 | if( entry->IsElementOfType( package_key ) ) |
802 | 803 | { |
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... | |
809 | 807 | */ |
810 | 808 | ct = 0; |
811 | - /* ...print the standard form package name header... | |
812 | - */ | |
813 | 809 | 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 ); | |
814 | 815 | if( dir != NULL ) |
815 | 816 | { |
816 | - /* ...with included enumeration of the component names... | |
817 | + /* ...to be printed in alphanumerically sorted order of | |
818 | + * component names... | |
817 | 819 | */ |
818 | 820 | dir->InOrder( this ); putchar( '\n' ); |
819 | - /* | |
820 | - * ...before discarding the auxiliary directory. | |
821 | + | |
822 | + /* ...before discarding the auxiliary directory. | |
821 | 823 | */ |
822 | 824 | delete dir; |
823 | 825 | } |