ADC Home > Reference Library > Technical Notes > Legacy Documents > Carbon >

Legacy Documentclose button

Important: This document is part of the Legacy section of the ADC Reference Library. This information should not be used for new development.

Current information on this Reference Library topic can be found here:

Strip With _OpenResFile and _OpenRFPerm

CONTENTS

This Technical Note discusses a bug in _OpenResFile and _OpenRFPerm which can cause system crashes and what you can do to avoid this problem.

[Apr 01 1989]






Introduction

The traps _OpenResFile and _OpenRFPerm call some common code in 128K and later ROMs which was affected by some system patches for early print drivers. The problem is that the common code checks an attribute bit in the pointer to the string name to see if it is a dereferenced handle. If the pointer has the resource attribute bit set, the Resource Manager assumes that it is a dereferenced handle and calls _RecoverHandle. This usually works, but when the string is embedded in a code resource, the Resource Manager calls _RecoverHandle with an invalid master pointer.


Note:
In MPW C, this bug is not a problem, unless you use either the -b, -b2, or -b3 options, which embed string constants in the code segment. If you use these options, you must deal with this bug.


The following code fragments give an example of this bug:

MPW Pascal

    VAR
        fileName : Str255;
        ref : INTEGER;

    BEGIN
        fileName := 'This File';
        ref := OpenResFile(fileName);

MPW C

    Str255        fileName;
    short int    ref;

    fileName = 'This File';

Calling _StripAddress on the pointer to the filename prior to calling _OpenResFile or _OpenRFPerm solves the problem:

MPW Pascal

    VAR
        fileName : Str255;
        ref : INTEGER;

    BEGIN
        fileName := 'This File';
        ref := OpenResFile(StringPtr(StripAddress(@fileName))^);

MPW C

    Str255        fileName;
    short int    ref;

    fileName = 'This File';

By always calling _StripAddress before calling _OpenResFile or _OpenRFPerm, you will not have to deal with this problem, life will be good, and you will be able to rest a bit easier.

Back to top

References

M.OV.32BitClean

M.ME.StripAddress

Back to top

Downloadables

Acrobat gif

Acrobat version of this Note (44K).

Download



Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.