If the field text was set with FldSetTextPtr, then calling FldGetTextHandle
won't do any good; the returned handle would be NULL. If the field text was set
with FldSetTextHandle, then calling FldGetTextPtr should return a pointer within
the already-locked memory chunk, in which case calling FldGetTextHandle and
locking the handle doesn't help. But even if I'm wrong about that second part
and the memory chunk is actually unlocked, then Alan should be getting a "read
from an unlocked memory chunk" error, not a "read from unallocated chunk" error.
At any rate, I think the problem is that fldText needs to be at least pwdLength
bytes long. If not, then the call to MemMove in PwdVerify will attempt to copy
bytes extending past the end of fldText. If (fldText + pwdLength - 1) happens to
be an unallocated memory chunk, then you'd get this error message.
Unless PwdVerify is documented as requiring that the input buffer be pwdLength
characters long, then I'd say this is a bug in PwdVerify; it shouldn't be
reading more characters than are provided.
Looking at the code for the Owner panel, I see that it works around this problem
by converting the password to lower case by placing the resulting string in a
pwdLength character buffer, rather than converting it in-place.
-- Keith Rollin
-- Palm OS Emulator engineer
Jason Garrett <[EMAIL PROTECTED]> on 06/16/99 10:40:53 PM
Please respond to [EMAIL PROTECTED]
Sent by: Jason Garrett <[EMAIL PROTECTED]>
To: "'palm-dev-forum @3com.com'" <[EMAIL PROTECTED]>
cc: (Keith Rollin/HQ/3Com)
Subject: RE: PwdVerify() giving a 'reading from unalloc. chunk' error in P OSER
You're not the only one who is trying to get a grasp on this.
I have a similar problem. I believe the answer to yours is:
You need to lock the field handle down first, then get the text ptr
and then copy it, finally unlocking.
ie:
VoidHand h = FldGetTextHandle((FieldPtr) FrmGetObjectPtr( frm,
FrmGetObjectIndex( frm, PasswordNameField)));
fldText = (CharPtr)MemHandleLock(h);
if (!fldText) goto DoDialog; // wow, a goto! My Comp.Sci threw a
duster at us for doing that
StrToLower(fldText, fldText); // I didn't know you could do this,
but that doesn't say much
... // whatever code is necessary
MemHandleUnlock(h);
Hope that helps. Let me know if I'm wrong!
> -----Original Message-----
> From: Alan Pinstein [SMTP:[EMAIL PROTECTED]]
> Sent: Thursday, June 17, 1999 5:20 PM
> To: [EMAIL PROTECTED]
> Subject: PwdVerify() giving a 'reading from unalloc. chunk' error in
> POSER
>
> [no ideas? anyone? bueller? bueller?... gremlins is complaining!
> thanks for any thoughts]
>
> Hi all-
> I am going nuts here trying to figure out why POSE is complaing about
> reading directly from an unallocated chunk of memory in this routine:
>
> static Boolean GetPassword()
> {
> FormPtr frm;
> CharPtr fldText;
>
> // if no password exists we don't even need to ask...
> if (!PwdExists())
> return true;
>
> frm = FrmInitForm(PasswordForm);
> FrmSetFocus(frm, FrmGetObjectIndex(frm, PasswordNameField));
>
> DoDialog:
>
> if (FrmDoDialog(frm) == PasswordCancelButton) {
> FrmDeleteForm(frm);
> return false;
> }
>
> fldText = (CharPtr)FldGetTextPtr((FieldPtr)FrmGetObjectPtr(frm,
> FrmGetObjectIndex(frm, PasswordNameField)));
>
> if (!fldText)
> goto DoDialog;
>
> StrToLower(fldText, fldText);
>
> if ( PwdExists() && !PwdVerify(fldText) ) { // *** crashing
> here in a MemMove in PwdVerify() ***
> FrmAlert(BadPasswordAlert);
> goto DoDialog;
> }
>
> FrmDeleteForm(frm);
>
> return true;
> }
>
> I've put a breakpoint in before the error and checked in the console to
> make sure that there is an allocated chunk in fldText, which theere is.
> I've also checked to make sure that it's not corrupted, and it isn't...
>
> I think I'm doing everything cleanly, but I must not be, unless there is a
> bug within PwdVerify(). I've tried it on everything from OS 2 to OS 3.1.
>
> Thanks for any help!
>
>
> Alan Pinstein
> Synergy Solutions, Inc.
> http://www.synsolutions.com
> 1-800-210-5293