@@ -337,46 +337,56 @@ unsigned long AdafruitIO_Data::toUnsignedLong()
337
337
338
338
int AdafruitIO_Data::toRed ()
339
339
{
340
- if (! _value)
341
- return 0 ;
342
-
343
- char r[] = " 0x" ;
344
- strncat (r, toChar () + 1 , 2 );
345
-
346
- return (int )strtol (r, NULL , 0 );
340
+ // Convert 0xRRGGBB to red.
341
+ if (! _value)
342
+ {
343
+ return 0 ;
344
+ }
345
+ char r[5 ];
346
+ strcpy (r, " 0x" );
347
+ strncpy (&r[2 ], toChar () + 1 , 2 );
348
+ r[4 ] = ' \x00 ' ;
349
+ return (int )strtol (r, NULL , 0 );
347
350
}
348
351
349
352
int AdafruitIO_Data::toGreen ()
350
353
{
351
- if (! _value)
352
- return 0 ;
353
-
354
- char g[] = " 0x" ;
355
- strncat (g, toChar () + 3 , 2 );
356
-
357
- return (int )strtol (g, NULL , 0 );
354
+ // Convert 0xRRGGBB to green.
355
+ if (! _value)
356
+ {
357
+ return 0 ;
358
+ }
359
+ char g[5 ];
360
+ strcpy (g, " 0x" );
361
+ strncpy (&g[2 ], toChar () + 3 , 2 );
362
+ g[4 ] = ' \x00 ' ;
363
+ return (int )strtol (g, NULL , 0 );
358
364
}
359
365
360
366
int AdafruitIO_Data::toBlue ()
361
367
{
362
- if (! _value)
363
- return 0 ;
364
-
365
- char b[] = " 0x" ;
366
- strncat (b, toChar () + 5 , 2 );
367
-
368
- return (int )strtol (b, NULL , 0 );
368
+ // Convert 0xRRGGBB to blue.
369
+ if (! _value)
370
+ {
371
+ return 0 ;
372
+ }
373
+ char b[5 ];
374
+ strcpy (b, " 0x" );
375
+ strncpy (&b[2 ], toChar () + 5 , 2 );
376
+ b[4 ] = ' \x00 ' ;
377
+ return (int )strtol (b, NULL , 0 );
369
378
}
370
379
371
380
long AdafruitIO_Data::toNeoPixel ()
372
381
{
373
- if (! _value)
374
- return 0 ;
375
-
376
- char rgb_string[9 ] = " 0x" ;
377
- strncat (rgb_string, toChar () + 1 , 6 );
378
-
379
- return strtol (rgb_string, NULL , 0 );
382
+ if (! _value)
383
+ {
384
+ return 0 ;
385
+ }
386
+ char rgb[9 ];
387
+ strcpy (rgb, " 0x" );
388
+ strncpy (&rgb[2 ], toChar () + 1 , 6 );
389
+ return strtol (rgb, NULL , 0 );
380
390
}
381
391
382
392
char * AdafruitIO_Data::toCSV ()
0 commit comments