Re: ubitx #v6 Screen Speed Mod #v6

Jack, W8TEE

Well, you may not see any reason to have it, but I do. Local buffer space is allocated on the stack, which means it contains garbage when the buffer space is created. The strcat() functions work by locating the first NULL character in the string space and appending after that. Given that the buffer can contain almost anything when created, the first NULL could be 50 bytes away from buff[0], which means that you probably just clobbered whatever was "behind" buff on the stack, which could well be the stack pointer. If that happens, your program wanders into Never-Never Land and who knows what happens next. You can leave the memset() call out of the code, but chances are 1 in 256 it won't work properly.

Also, in the code below, where is variable b defined?

Jack, W8TEE

On Friday, January 17, 2020, 9:59:20 AM EST, Gary Anderson <gary.ag5tx@...> wrote:

I see no reason to do the memset in this function.  Removed it.  Less program space used and less processing cycles.
Added a rounding option, that is commented out.  More program space and processing cycles :)
Wrote a simple sketch that ran through a list of frequencies and then printed buff to STDOUT.
I will get a GitHub account so I can play better in the future.

void formatFreq(long f, char *buff) {
  // tks Jack Purdum W8TEE
  // replaced fsprint commmands by str commands for code size reduction
  // AG5TX
  // resolved issue with format below 1 MHz, there is an issue below 100 Hz
  // rounding uses more bytes of program storage space and adds processing cycles
  // uncomment if you want this feature
  // round up for when only 2 digits after decimal point are used
  if(f%10 >= 5) {
    f += 5;
  ultoa(f, b, DEC);
  int g = strlen(b);
  for (int i = g; i < 8 ; i++){
     strcat(buff, " ");
  strncat(buff, b, g-3);
  strcat(buff, ".");
  strncat(buff, &b[g-3], 2); // could set last arg to 3 for 3 digits after dec point, just don't round up.

Jack, W8TEE

Join to automatically receive all group messages.