I get a warning that square might be used uninitialized and that seems to be the problem indeed.
However, it seems strange that you are outputting while the timing. Printing to console is a rather slow and it would make more sense to time how long it takes to generate primes up to [various sizes] and only then may-be validate that they are actually right, for example against a known list.