> таки НЕ работает :^( сегфолтитцца
:(
Из man strcat:
... The strings may not overlap,...
Глупость какая! Не ожидал...
Тогда только так:
(char*)memmove(str+firstchar,str+firstchar+count)-firstchar
Самому проще налабать:
char *delete(char *str, int firstchar, int count)
{
char *tmp=str+firstchar;
while(*tmp=*(tmp+count))tmp++;
return str;
}
1.c: (in function panic)
1.c:8:4: Return value (type int) ignored: fputs("Panic! ",...
Result returned by function call is not used. If this is intended, can cast
result to (void) to eliminate message. (Use -retvalint to inhibit warning)
1.c:9:4: Return value (type int) ignored: fputs(msg, stderr)
1.c:10:4: Return value (type int) ignored: fputs("\nSerious...
1.c:11:4: Return value (type int) ignored: fputs("Immediate...
1.c:12:9: Argument to exit has implementation defined behavior: 255
The argument to exit should be 0, EXIT_SUCCESS or EXIT_FAILURE (Use -exitarg
to inhibit warning)
1.c: (in function onSegV)
1.c:23:12: Fall through case (no preceding break)
Execution falls through from the previous case. (Use -casebreak to inhibit
warning)
1.c:25:15: Fall through case (no preceding break)
1.c:18:25: Parameter i not used
A function parameter is not used in the body of the function. If the argument
is needed for type compatibility or future plans, use /*@unused@*/ in the
argument declaration. (Use -paramuse to inhibit warning)
1.c: (in function delete)
1.c:42:4: Return value (type [function (int) returns void]) ignored:
signal(SIGSEGV, ...
Result returned by function call is not used. If this is intended, can cast
result to (void) to eliminate message. (Use -retvalother to inhibit warning)
1.c:46:31: Left operand of <<= may be negative (int): maxint <<= 1
The left operand to a shift operator may be negative (behavior is
implementation-defined). (Use -shiftimplementation to inhibit warning)
1.c:49:17: Index of possibly null pointer str: str
A possibly null pointer is dereferenced. Value is either the result of a
function which may return null (in which case, code should check it is not
null), or a global, parameter or structure field declared with the null
qualifier. (Use -nullderef to inhibit warning)
1.c:63:4: Return value (type [function (int) returns void]) ignored:
signal(SIGSEGV, ...
1.c:64:11: Implicitly temp storage str returned as implicitly only: str
Temp storage (associated with a formal parameter) is transferred to a
non-temporary reference. The storage may be released or new aliases created.
(Use -temptrans to inhibit warning)
Ты привел результат прогона на предмет поиска мест,
где чисто синтаксически возможны неоднозначности.
Какой конкретно из приведенных тобой варнингов (кроме
специально идиотски сделанной функции panic) тебя
беспокоит?
Перехвачено все; не только нулевые указатели, (что, BTW,
вообще было совершенно лишнее), но и даже возможность
mprotectнутости региона.
Проверялка, кстати, довольно тупа. Например,
> 1.c:64:11: Implicitly temp storage str returned as implicitly only: str
Temp storage (associated with a formal parameter) is transferred to a
non-temporary reference.
Очевидная чушь, ибо возвращается в точности тот же storage класс,
что и прилетел; никаких манипуляций с указателем сделано не было.
Возможность нулевого значения str на строке 49 почему-то указана
(несмотря на предшествующую проверку!), а возможность
выхода за границы памяти и перполнения целого в той же строке
игнорируется.
>- незачем возвращать 255, используя для exit() stdlib.h в
>которой кроме EXIT_FAILURE и EXIT_SUCCES ничего нет
В POSIXе есть. И в подавляющем большинстве прочих систем есть.
EXIT_FAILURE и EXIT_SUCCES определены в stdlib.h только для
совместимости с некоторыми экзотическими системами.
$cat ququ.c
#include <stdlib.h>
int main(void)
{
exit(255);
}
$cc -o ququ ququ.c
$./ququ ; echo $?
255
(BTW, такое идиотское значение задавалось специально; надо
было вообще -1 влепить -- догадаешься, что будет?)
> - незачем функциям тип int, если он нигде не используется.
А где ты увидел в моем примере возвращаемый тип int?
Если рассматривать ЮНИХ системы, то в примере только одна натяжка:
тип сигнального хандлера на некоторых системах не void a int.
А сам пример, если кто в танке, был призван продемонстрировать
дебилизм борьбы пионеров за безопасность (в безопасных программах
не может возникнуть необходимости в функции delete()).
имхо писать приложения надо так чтобы в них было только _необходимое_, и все что передается от пользователя, возвращается от функций и статусы возврата тоже - изначально считались потенциально опасными
я стараюсь думать по шаблону
s/А что в этом опасного/Зачем это здесь необходимо/