Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Trac #33210: fix uninitialized pointer use in polynomial_modn_dense_n…
Browse files Browse the repository at this point in the history
…tl.pyx.

Cython is kind enough to point out the following,

  warning: sage/rings/polynomial/polynomial_modn_dense_ntl.pyx:876:32:
  local variable 'mod' referenced before assignment

which references the following (paraphrased) code:

  cdef zz_pX_Modulus_c *mod
  zz_pX_Modulus_build(mod[0], (<Polynomial_dense_modn_ntl_zz>modulus).x)

That's declaring a pointer "mod", and then overwriting the structure
that it points to with pre-computed information about "modulus.x". But
where does "mod" point?

Instead, the first line should be allocating space for a structure
that can then be passed by reference directly (i.e. without indexing)
to zz_pX_Modulus_build. This fix is made in two places, and as a
side-effect, eliminates the Cython warnings.
  • Loading branch information
orlitzky committed Jan 21, 2022
1 parent f9b2db9 commit b0fcca3
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ cdef class Polynomial_dense_modn_ntl_zz(Polynomial_dense_mod_n):
return self.parent(1)

cdef Polynomial_dense_modn_ntl_zz r = self._new()
cdef zz_pX_Modulus_c *mod
cdef zz_pX_Modulus_c mod

self.c.restore_c()

Expand All @@ -873,11 +873,11 @@ cdef class Polynomial_dense_modn_ntl_zz(Polynomial_dense_mod_n):
else:
if not isinstance(modulus, Polynomial_dense_modn_ntl_zz):
modulus = self.parent()._coerce_(modulus)
zz_pX_Modulus_build(mod[0], (<Polynomial_dense_modn_ntl_zz>modulus).x)
zz_pX_Modulus_build(mod, (<Polynomial_dense_modn_ntl_zz>modulus).x)

do_sig = zz_pX_deg(self.x) * e * self.c.p_bits > 1e5
if do_sig: sig_on()
zz_pX_PowerMod_long_pre(r.x, self.x, e, mod[0])
zz_pX_PowerMod_long_pre(r.x, self.x, e, mod)
if do_sig: sig_off()

if recip:
Expand Down Expand Up @@ -1416,7 +1416,7 @@ cdef class Polynomial_dense_modn_ntl_ZZ(Polynomial_dense_mod_n):
if self == 0 and e == 0:
return self.parent(1)
cdef Polynomial_dense_modn_ntl_ZZ r = self._new()
cdef ZZ_pX_Modulus_c *mod
cdef ZZ_pX_Modulus_c mod

self.c.restore_c()

Expand All @@ -1431,11 +1431,11 @@ cdef class Polynomial_dense_modn_ntl_ZZ(Polynomial_dense_mod_n):
else:
if not isinstance(modulus, Polynomial_dense_modn_ntl_ZZ):
modulus = self.parent()._coerce_(modulus)
ZZ_pX_Modulus_build(mod[0], (<Polynomial_dense_modn_ntl_ZZ>modulus).x)
ZZ_pX_Modulus_build(mod, (<Polynomial_dense_modn_ntl_ZZ>modulus).x)

do_sig = ZZ_pX_deg(self.x) * e * self.c.p_bits > 1e5
if do_sig: sig_on()
ZZ_pX_PowerMod_long_pre(r.x, self.x, e, mod[0])
ZZ_pX_PowerMod_long_pre(r.x, self.x, e, mod)
if do_sig: sig_off()
if recip:
return ~r
Expand Down

0 comments on commit b0fcca3

Please sign in to comment.