When working with embedded systems, it is sometimes important to do dirty little hacks. There are many ways to call upon the dark magic, though a large number of them are pointer or string tricks, often sacrificing readability and portability for memory or performance. There is a local benefit.

As a contractor, James runs in to his fair share of funny things in firmware. The following code, however, did not make him laugh.

 

  // write the message to a buffer
  char buffer[N];
  sprinf(buffer, "%s: %s\n\r",header,value);

  // remove the carriage return
  int len = strlen(buffer);
  buffer[len-2] = 0;

 

You'll get bonus points if you can figure out why I think strlen is redundant.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!