Commit 78dc052d9980f27a505041f8609952a683d50519

Authored by Adeel Kazmi
1 parent 690432ce

(Deferred Shading) Fix some SVACE errors

1) Should use snprintf instead of sprintf
2) Should use strncpy instead of strcpy

Change-Id: If13366f0f176fdad3948bc1e8e425e430c233fc6
examples/deferred-shading/deferred-shading.cpp
@@ -458,6 +458,26 @@ void RegisterDepthProperties(float depth, float near, Handle& h) @@ -458,6 +458,26 @@ void RegisterDepthProperties(float depth, float near, Handle& h)
458 } 458 }
459 459
460 //============================================================================= 460 //=============================================================================
  461 +/// Create a String whose size can be evaluated at compile time
  462 +struct ConstantString
  463 +{
  464 + const char * const string;
  465 + const uint16_t size;
  466 +
  467 + template<uint16_t inputSize>
  468 + constexpr ConstantString(const char (&input)[inputSize])
  469 + : string(input),
  470 + size(inputSize)
  471 + {
  472 + }
  473 +};
  474 +
  475 +constexpr ConstantString POSITION_STRING("position");
  476 +constexpr ConstantString RADIUS_STRING("radius");
  477 +constexpr ConstantString COLOR_STRING("color");
  478 +constexpr uint16_t LIGHT_SOURCE_BUFFER_SIZE(128u);
  479 +
  480 +//=============================================================================
461 class DeferredShadingExample : public ConnectionTracker 481 class DeferredShadingExample : public ConnectionTracker
462 { 482 {
463 public: 483 public:
@@ -711,17 +731,17 @@ private: @@ -711,17 +731,17 @@ private:
711 auto iPropLightColor = light.RegisterProperty("lightcolor", color); 731 auto iPropLightColor = light.RegisterProperty("lightcolor", color);
712 732
713 // Create light source uniforms on lighting shader. 733 // Create light source uniforms on lighting shader.
714 - char buffer[128];  
715 - char* writep = buffer + sprintf(buffer, "uLights[%d].", mNumLights); 734 + char buffer[LIGHT_SOURCE_BUFFER_SIZE];
  735 + char* writep = buffer + snprintf(buffer, LIGHT_SOURCE_BUFFER_SIZE, "uLights[%d].", mNumLights);
716 ++mNumLights; 736 ++mNumLights;
717 737
718 - strcpy(writep, "position"); 738 + strncpy(writep, POSITION_STRING.string, POSITION_STRING.size);
719 auto oPropLightPos = renderer.RegisterProperty(buffer, position); 739 auto oPropLightPos = renderer.RegisterProperty(buffer, position);
720 740
721 - strcpy(writep, "radius"); 741 + strncpy(writep, RADIUS_STRING.string, RADIUS_STRING.size);
722 auto oPropLightRadius = renderer.RegisterProperty(buffer, radius); 742 auto oPropLightRadius = renderer.RegisterProperty(buffer, radius);
723 743
724 - strcpy(writep, "color"); 744 + strncpy(writep, COLOR_STRING.string, COLOR_STRING.size);
725 auto oPropLightColor = renderer.RegisterProperty(buffer, color); 745 auto oPropLightColor = renderer.RegisterProperty(buffer, color);
726 746
727 // Constrain the light position, radius and color to lighting shader uniforms. 747 // Constrain the light position, radius and color to lighting shader uniforms.