Permalink
Browse files

added more detailed documentation about Crypt::GCrypt::MPI::copy() vs =

git-svn-id: svn://localhost/Crypt-GCrypt/trunk@79 c2f821fb-fd85-dc11-8383-000bcdcb7a8f
  • Loading branch information...
1 parent 171727b commit 1e27dd20b26937caa77323fce4e556bc3ebc4406 dkg committed Jan 18, 2010
Showing with 9 additions and 5 deletions.
  1. +9 −5 lib/Crypt/GCrypt/MPI.pm
View
14 lib/Crypt/GCrypt/MPI.pm
@@ -101,14 +101,18 @@ greater, negative if $other is greater.
=head2 copy()
Returns a new Crypt::GCrypt::MPI object, with the contents identical
-to this one. This is distinct from using the assignment operator (=).
+to this one. This is better than using the assignment operator (=).
For example:
$b = new Crypt::GCrypt::MPI(15);
- $a = $b;
- $b->add(1); # $a points to the same object, so both $a and $b contain 16.
-
- $a = $b->copy(); # $a and $b are both 16, but different objects
+ $a = $b; # DANGER! this may cause a double-free
+ # when $a and $b fall out of scope.
+ $b->add(1); # $a points to the same object,
+ # so both $a and $b contain 16.
+
+ $a = $b->copy(); # $a and $b are both 16, but
+ # different objects; no risk of
+ # double-free.
$b->add(1); # $a == 16, $b == 17
If $b is a Crypt::GCrypt::MPI object, then "$a = $b->copy();" is

0 comments on commit 1e27dd2

Please sign in to comment.