Of all the many, many improbable elements involved in the Curiosity Mars Rover - it's massive size (two tons), its cost ($2.5bn) and its hauntingly elegant descent via levitating sky crane - the software it runs doesn't get much attention. And the people who checked that code for errors? Even less so.

But consider this: all of the code involved in the entire Apollo 11 mission numbered roughly a few thousand lines. For Curiosity it's about two million.

That's a lot. And unlike back here on Earth, you can't just release buggy code and rely on patch updates to keep it working. If Curiosity crashes, there's a chance it could transform from the greatest mobile science lab ever constructed into a $2bn paperweight, overnight.

So it's no surprise that when Nasa decided to check its code for errors, they weren't messing about.

Enter Coverity, the international software analysis company who - for want of a better phrase - are Curiosity's doctor of choice.

Coverity were recruited by Nasa's Jet Propulsion Laboratory to help analyse the code behind Curiosity, from the relatively early stages of development right up until, well - now.

"As a kid I always imagined I'd be an astronaut," Andy Chou, CTO and co-founder of Coverity, told the Huffington Post.

"I think most people love the idea of space travel, and it's just really exciting that we did something like this."

Chou said that while the world's most iconic space agency obviously checks its own software, there are times when even Nasa needs to call in greater expertise.

"As software gets larger it becomes more difficult to test it thoroughly," he explained. "Two million lines of code is quite a lot. It's virtually impossible to test a software system with that much code with just ordinary testing, so they turned to other techniques. Our products use an an analysis technique called Static Analysis (SA), which automatically analyses the code and looks at all the different paths through it so we don't miss anything."

That work involved spending months modifying its SA products, and working constantly with Nasa to check and recheck its code.

Chou explains that Nasa is obsessive about looking for errors.

It took a few months to modify Coverity's products for the Nasa mission, and once they started the scans happened constantly. "New defects were being found as the code was freshly written," Chou said.

"They were very, very careful. Even just the hint of something complex and not easily understood was enough for them to rewrite parts of their code."

Even now the rover is on Mars and making progress to its first major scientific targets, Coverity are still involved. The rover will spend two years on the surface looking for evidence of life, investigating the landscape and sending back photos. Updates to the rover's software could potentially still be pushed to Mars, and Coverity would still be part of that process.

"The software was being updated even while the rover was in transit to Mars," he said. "In fact they have the capability of uploading new software even now. It's pretty remarkable if you think about it - that's a large amount of code and for something like this to get pulled off without a hitch is pretty amazing.

"Most software when it goes into production doesn't work flawlessly. Most software has some failure and patches get put out and people have to update that software - even pretty high-end mission critical software has issues, such as software used in financial exchanges, often have to be closely watched. The fact that this just worked the very first time - that's the remarkable part."

Loading Slideshow...
  • In this image released by NASA on Monday, Aug. 27, 2012, a chapter of the layered geological history of Mars is laid bare in this color image from NASA's Curiosity rover showing the base of Mount Sharp, the rover's eventual science destination. The image is a portion of a larger image taken by Curiosity's 100-millimeter Mast Camera on Aug. 23, 2012. Scientists enhanced the color in one version to show the Martian scene under the lighting conditions we have on Earth, which helps in analyzing the terrain. The pointy mound in the center of the image, looming above the rover-sized rock, is about 1,000 feet (300 meters) across and 300 feet (100 meters) high. (AP Photo/NASA/JPL-Caltech/MSSS)

  • In this image released by NASA on Monday, Aug. 27, 2012, an image taken by the Mast Camera (MastCam) highlights the geology of Mount Sharp, a mountain inside Gale Crater, where the rover landed. Prior to the rover's landing on Mars, observations from orbiting satellites indicated that the lower reaches of Mount Sharp, below the line of white dots, are composed of relatively flat-lying strata that bear hydrated minerals. Those orbiter observations did not reveal hydrated minerals in the higher, overlying strata. The MastCam data now reveal a strong discontinuity in the strata above and below the line of white dots, agreeing with the data from orbit. Strata overlying the line of white dots are highly inclined (dipping from left to right) relative to lower, underlying strata. The inclination of these strata above the line of white dots is not obvious from orbit. This provides independent evidence that the absence of hydrated minerals on the upper reaches of Mount Sharp may coincide with a very different formation environment than lower on the slopes. The train of white dots may represent an "unconformity," or an area where the process of sedimentation stopped. (AP Photo/NASA/JPL-Caltech/MSSS)

  • In this image released by NASA on Monday, Aug. 27, 2012, An image from a test series used to characterize the 100-millimeter Mast Camera on NASA's Curiosity rover taken on Aug. 23, 2012, looking south-southwest from the rover's landing site. The 100-millimeter Mastcam has three times better resolution than Curiosity's 34-millimeter Mastcam, though it has a narrower field of view. The gravelly area around Curiosity's landing site is visible in the foreground. Farther away, about a third of the way up from the bottom of the image, the terrain falls off into a depression (a swale). Beyond the swale, in the middle of the image, is the boulder-strewn, red-brown rim of a moderately-sized impact crater. Farther off in the distance, there are dark dunes and then the layered rock at the base of Mount Sharp. Some haze obscures the view, but the top ridge, depicted in this image, is 10 miles (16.2 kilometers) away. Scientists enhanced the color in one version to show the Martian scene under the lighting conditions we have on Earth, which helps in analyzing the terrain. (AP Photo/NASA/JPL-Caltech/MSSS)

  • In this image released by NASA on Monday, Aug. 27, 2012, a photo taken by the Mast Camera (MastCam) highlights the geology of Mount Sharp, a mountain inside Gale Crater, where the rover landed. Prior to the rover's landing on Mars, observations from orbiting satellites indicated that the lower reaches of Mount Sharp, below the line of white dots, are composed of relatively flat-lying strata that bear hydrated minerals. Those orbiter observations did not reveal hydrated minerals in the higher, overlying strata. The MastCam data now reveal a strong discontinuity in the strata above and below the line of white dots, agreeing with the data from orbit. Strata overlying the line of white dots are highly inclined (dipping from left to right) relative to lower, underlying strata. The inclination of these strata above the line of white dots is not obvious from orbit. This provides independent evidence that the absence of hydrated minerals on the upper reaches of Mount Sharp may coincide with a very different formation environment than lower on the slopes. The train of white dots may represent an "unconformity," or an area where the process of sedimentation stopped. (AP Photo/NASA/JPL-Caltech/MSSS)

  • Mike Malin, John Grotzinger, Paul Mahaffy, Chad Edwards

    Chad Edwards, chief telecommunications engineer for NASA's Mars Exploration Program, far right, explains how an international network of telecommunications relay orbiters bring data back from Mars during a briefing at NASA's Jet Propulsion Laboratory in Pasadena, Calif., Monday, Aug. 27, 2012. Curiosity already has returned more data from the Martian surface than have all of NASA's earlier rovers combined. Relay robotic spacecraft orbiting Mars seen on graphic: NASA's Mars Reconnaissance Orbiter, MRO, and Mars Odyssey ODY. Scientists from left: Mike Malin, imaging scientist for the Mars Science Laboratory, John Grotzinger, MSL project scientist, California Institute of Technology, Paul Mahaffy, NASA Goddard Space Flight Center, and Dr. Edwards. (AP Photo/Damian Dovarganes)

So why did - does - the Curiosity rover capture people's imagination? Is it just the audacity of the project, the chance of finding evidence of life - or just the fact that the craft has its own Twitter feed?

Chris Adlard, senior manager for customer advocacy at Coverity, said that the robot has a tangible personality lacking from other massive science experiments, for instance the CERN Large Hadron Collider (on which Coverity also worked).

It's the fact that it's so personified," he said. :If you look at the commentary over Twitter for the rover, it's almost as if Curiosity itself is talking to you. It's much more immediate to the everyday person than other previous missions. "


Curiosity Rover
FORE! I completed my longest drive ever. On sol 50, I rolled another ~160 feet (48.9 meters) toward Glenelg

Chou agrees. "There are very few things these days that can inspire where it comes to science and it's often esoteric, and this is just very concrete. An actual space craft has been sent out there," he said.

For all Coverity's insanely rigorous work on the rover, they recognise they were still only involved in one small element of its success. But the fact is that in modern science, where so much depends on hugely expensive experiments finding new, precious data for analysis, it is only in collaboration of this kind that the real advances may be made.

"There is so much data involved in modern science, processing that data and having software that can automate what would otherwise be impossible manually is critical," Chou said. "That's just a reality of how science is done today."

So to any young coders out there - you might not get to be the astronaut you dreamed of being as a kid. But fixing software bugs on Mars? Well, that's pretty cool too.