Skip to content

Commit

Permalink
additional checks before calling
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonidPryadko committed Jan 12, 2024
1 parent 4d13a35 commit b16a452
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 10 additions & 2 deletions lib/qdistrnd.g
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,21 @@ BindGlobal("QDR_ParseFieldStr",
);

#! @Description Parse string `str` as a polynomial over the field `F`.
#! No spaces are allowed.
#! Only characters in "0123456789*+-^x" are allowed in the string.
#! In particular, no spaces are allowed.
#! @Returns the corresponding polynomial
#! @Arguments F, str
#DeclareGlobalFunction("QDR_ParsePolyStr");
BindGlobal("QDR_ParsePolyStr",
function(F, str)
local func;
local func, new_str;
# make sure `str` only contains these characters
new_str := String(str); # copy
RemoveCharacters(new_str,"0123456789x*+-^");
if (Length(new_str) > 0) then
ERROR("QDR_ParsePolyStr: invalid character(s) [",new_str,"] in polynomial ",str);
fi;

func := EvalString(Concatenation("""
function(F)
local x;
Expand Down
8 changes: 4 additions & 4 deletions tst/qdistrnd02.tst
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ gap> H:=One(F)*[[1,0, -1,0, 0,0, 0,0 ], # original Hx in odd positions
gap> DistRandStab(H,100,0,2 : field:=F);
2

# doc/_Chapter_AllFunctions.xml:485-488
# doc/_Chapter_AllFunctions.xml:486-489
gap> QDR_AverageCalc([2,3,4,5]);
3.5

# doc/_Chapter_AllFunctions.xml:491-502
# doc/_Chapter_AllFunctions.xml:492-503
gap> F:=GF(3);;
gap> x:=Indeterminate(F,"x");; poly:=One(F)*(1-x);;
gap> n:=5;;
Expand All @@ -45,7 +45,7 @@ gap> Display(mat);
. . . . . . 1 2 . .
. . . . . . . . 1 2

# doc/_Chapter_AllFunctions.xml:506-517
# doc/_Chapter_AllFunctions.xml:507-518
gap> QDR_ParseFieldStr("Z(5)");
Z(5)
gap> QDR_ParseFieldStr("Z(17)");
Expand All @@ -57,7 +57,7 @@ GF(5^2)
gap> QDR_ParseFieldStr("GF(125^2)");
GF(5^6)

# doc/_Chapter_AllFunctions.xml:520-523
# doc/_Chapter_AllFunctions.xml:521-524
gap> QDR_ParsePolyStr(GF(25),"x^2+1");
x^2+Z(5)^0

Expand Down

0 comments on commit b16a452

Please sign in to comment.